django-render

Django templates render sugar
Download

django-render Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Other/Proprietary Li...
  • Price:
  • FREE
  • Publisher Name:
  • Alexandr I. Shurigin
  • Publisher web site:
  • https://github.com/phpdude/

django-render Tags


django-render Description

django-render is a Django app that provides decorators for templates rendering and CBV mixin in request context with simple code use.Important: all template renders goes in request context. Sessions, cookies, meta, etc is available from templates.Usage in functional viewsIt support simple template rendering with decorator function. It is basic use example. Will be rendered template "APPNAME/VIEWNAME.html"from render.template import render@renderdef index(): #index view logic goes here return { 'var1': val1, 'var2': val2, }from render.template import render@renderdef index(): #index view logic goes here return { 'var1': val1, 'var2': val2, }, 'text/plain'You can override VIEWNAME part in template path. See example.from render.template import render@renderdef all(): #all view logic goes here return 'index.html', { 'var1': val1, 'var2': val2, }You can override APPNAME part in template path. See example.from render.template import renderer@renderer("otherapp")def all(): #all view logic goes here return 'index.html', { 'var1': val1, 'var2': val2, }Or you can return "ready to use HttpResponse" object. render wrapepr just return it.from render.template import render@renderdef all(): if some_logic: return HttpResponse("It's ok too") #all view logic goes here return 'index.html', { 'var1': val1, 'var2': val2, }Usage in Class Based ViewsIt supports basic TemplateView's likeclass Index(RenderViewMixin, TemplateView): passIt calculates template name as APP/VIEW.htmlYou can override heuristic by declaring template_name variable likeclass Index(RenderViewMixin, TemplateView): template_name = 'custom.html'This call APP/custom.html. Or you can add full template path likeclass Index(RenderViewMixin, TemplateView): template_name = 'otherapp/custom.html'Then will be called 'otherapp/custom.html'Like functional view you can use render sugar in get/post/delete/etc request to your CBV.class Index(RenderViewMixin, TemplateView): def get(self, request, *args, **kwargs): return { "title": 'My awesome title!' }Supported all sugar with defining template name, context data and mimetype.class Index(RenderViewMixin, TemplateView): def get(self, request, *args, **kwargs): return 'print.html', { "title": 'My awesome title!' }, 'text/plain'It works and with global template_name defining.class Index(RenderViewMixin, TemplateView): template_name = 'default.html' def get(self, request, *args, **kwargs): return { "title": 'My awesome title!' }, 'text/plain'Template processingInto template context render add few variables.- App - Application name, where was called view- View - View function name- Layout - Base layout path. Compiles from APPNAME and base.html. Example: for news app it will be equal "news/base.html"Example in template: {% extends Layout %}< div class="{{ App }}_{{ View }}" >{% block content %}< /div >It is clean & dry helper! Use it :-)phpdudeProduct's homepage


django-render Related Software