djangosnippets.org: Latest snippets tagged with 'rendering'https://djangosnippets.org/tags/rendering/2010-03-04T21:21:20.575861-06:00DRY template rendering decorator update
2010-03-04T21:21:20.575861-06:00jakecrhttps://djangosnippets.org/snippets/1951/<p>Based fully on <a href="http://www.djangosnippets.org/snippets/1929/">snippet 1929</a></p>
<p><strong>The update is:</strong>
It checks to see the view returns an instance of HttpResponse and returns that rather than trying to render it.
This allows you to return something like <code>HttpResponseRedirect('/')</code>, or use a normal <code>render_to_response</code> to use a different template.</p>
<p><em>Also updates cleandict …</em></p>
Freely redistributableDRY template rendering decorator
2010-02-16T05:07:23.884179-06:00pfylimhttps://djangosnippets.org/snippets/1929/<p>in this case the 'render_template' decorator assumes there is a myview.html template. this keeps things simple and you DRY. Hope it helps.</p>
<p>Regards,
Paul</p>
Freely redistributablerender_with decorator
2008-09-04T14:47:09.672312-05:00tobiashttps://djangosnippets.org/snippets/1022/<p>Automatically render your view using render_to_response with the given template name and context, using RequestContext (if you don't know what this is you probably want to be using it). For example:</p>
<pre><code>@render_with('books/ledger/index.html')
def ledger_index(request):
return {
'accounts': ledger.Account.objects.order_by('number'),
}
</code></pre>
Freely redistributablerender_to
2008-06-24T06:18:08.817167-05:00asolovyovhttps://djangosnippets.org/snippets/821/<p>Decorator, written for views simplification. Will render dict, returned by view, as context for template, using RequestContext. Additionally you can override template, returning two-tuple (context's dict and template name) instead of just dict.</p>
<p>Usage:</p>
<pre><code>@render_to('my/template.html')
def my_view(request, param):
if param == 'something':
return {'data': 'some_data'}
else:
return {'data': 'some_other_data'}, 'another/template.html'
</code></pre>
Freely redistributableAuto rendering decorator with options
2008-01-22T10:21:09.404358-06:00Batistehttps://djangosnippets.org/snippets/559/<p>This view decorator renders automaticaly the template with the context provided both by the view "return" statement. For example:</p>
<pre><code>@auto_render
def my_view(request):
...
return 'base.html', locals()
</code></pre>
<p>You can still return HttpResponse and HttpResponseRedirect objects without any problems. If you use Ajax requests, this decorator is even more useful. Imagine this …</p>
Freely redistributableForm rendering using a template instead of builtin HTML
2007-06-04T08:56:05.482820-05:00leohhttps://djangosnippets.org/snippets/263/<p>As an alternative to using forms rendered with the
default hard-coded html, this factory function will
take a template name as argument, and return a Form class based on django.newforms.BaseForm, which will
render each form field using the supplied template.</p>
<p>As an example, I'm using this class as follows in …</p>
Freely redistributableWTForm (What The Form)
2007-05-03T13:52:06.707355-05:00chrjhttps://djangosnippets.org/snippets/214/<p>WTForm is an extension to the django newforms library allowing
the developer, in a very flexible way, to layout the form
fields using fieldsets and columns</p>
<p>WTForm was built with the well-documented <a href="http://developer.yahoo.com/yui/grids/">YUI Grid CSS</a> in
mind when rendering the columns and fields. This should make
it easy to implement …</p>
Freely redistributable