Skip to content

home page app fancy versionΒΆ

  • quick and dirty home page that has some dynamic features
  • makes routing initial urls to apps automatic
  • lists folders in your django app
  • excludes ones you do not want urls for
  • creates urls to your_apps/
  • start app
python startapp home 
  • rout in your initial
from home import views

    path('', views.homepage, name='home'),
  • home/
from django.shortcuts import render
from django.http import HttpResponse
from automation.gadget import findviews, getmodule, cleanlist

import os

def homepage(request):
    folders = next(os.walk('.'))[1]
    excluded = ['home',
    folders = [f for f in folders if f not in (excluded)]
    folders = sorted(folders)
    html = """
            <h4>tests topics</h4>
    for folder in folders:
        html += "<a class=\"mdl-button \" href=%s>%s</a>   " % (
            folder, folder)
    # return HttpResponse(html)
    return render(request, 'home/home.html', {'html':html})
import inspect
import imp

def getmodule(path):
    name = inspect.getmodulename(path)
    return name

def findviews(path):
    """input path output links to pages (function name)"""
    path = imp.load_source("__inspected__", path)
    all_functions = inspect.getmembers(path, predicate=inspect.isfunction)
        all_functions = sorted(all_functions)
        return all_functions
        return('no views found')

def cleanlist(item_list, exclude):
    """convert inspect tuple to list and apply exclude list"""
    # convert tuple to list
    list_string = []
    for item in item_list:
    # apply exclusions
    clean_list = []
    for e in list_string:
        if e not in exclude:
    item_list = clean_list
    return clean_list

def cleanhomelist(item_list, exclude):

if __name__ == '__main__':
  • home.html
{% extends "base.html" %} {% block title %}Homepage{% endblock %} {% block content %}
{% endblock %}

Last update: October 14, 2023
Created: October 14, 2023