fromdjango.shortcutsimportrenderfromdjango.httpimportHttpResponseimportglobimportosfromdjango.confimportsettingsMDBLOGFOLDER=os.path.join(settings.BASE_DIR,"whereveryouwant/")MDPAGES=glob.glob(MDBLOGFOLDER+'/*/')defblog(request):"""return blog folders"""directories=next(os.walk(MDBLOGFOLDER))[1]returnrender(request,'mdblog/directories.html',{'directories':directories})deffile_get_contents(filename):"""contents of one file"""withopen(filename,'r',encoding="utf-8")asf:returnf.read()defview_folder(request,folder):"""list files in one folder"""folder=MDBLOGFOLDER+folderhtml=""#r"<h3>%s</h3>" % folderhtml+="<ul>"ifos.path.isdir(folder):onlyfiles=[fforfinos.listdir(folder)ifos.path.isfile(os.path.join(folder,f))]forfinonlyfiles:html+=("<li>\n")html+="<a href=%s>%s</a>"%(f,f)html+=("</li>\n")else:html+=f"<br>folder: {folder} is empty"html+="</ul>"returnrender(request,'mdblog/folder.html',{'html':html,'folder':folder,})defview_file(request,folder,file):"""show one file"""html=""#r"<h3>%s</h3>" % folderhtml+='<h3>%s</h3>'%filecontents=file_get_contents(MDBLOGFOLDER+'/'+folder+'/'+file)html_end=""#"<a class=\"mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect \"\ href=%s>%s</a>" % ('', 'run')returnrender(request,'mdblog/file.html',{'html':html,'html_end':html_end,'contents':contents})