djangosnippets.org: Latest snippets tagged with 'render'https://djangosnippets.org/tags/render/2010-03-11T03:55:08.475625-06:00Rendering radio-buttons with icons instead of labels
2010-03-11T03:55:08.475625-06:00jeverlinghttps://djangosnippets.org/snippets/1956/<p>I was looking for a way to save screen real estate, by using icons instead of labels for my list of choices, which in addition should be displayed as horizontal radio buttons.
For example, I wanted to use thumbs_up.gif instead of "approve".
I found a HorizontalRadioRenderer here:
</p>
<p><a href="https://wikis.utexas.edu/display/~bm6432/Django-Modifying+RadioSelect+Widget+to+have+horizontal+buttons">https://wikis.utexas.edu/display/~bm6432/Django-Modifying+RadioSelect+Widget+to+have+horizontal+buttons</a>
</p>
<p>Thanks to …</p>
Freely redistributableRender arbitrary models - template tag
2009-09-27T06:13:10.863275-05:00jeffschenckhttps://djangosnippets.org/snippets/1745/<p>This template tag provides an easy way to render objects in your template, even if you don't know ahead of time what type they are.
</p>
<p>For example, if you've got a search page with a result list comprised of objects from various models, you can simply loop through them and …</p>
Freely redistributableRender Decorator
2009-09-17T08:29:31.551007-05:00dahoolhttps://djangosnippets.org/snippets/1733/<p>Simple decorator to render an html template or return a json response. The view must return a dict object.</p>
<p>Usage example:</p>
<pre><code>@render('page.html')
def a_view(request):
#do something
return {'key': 'value'}
</code></pre>
Freely redistributableRender to email
2009-05-03T17:10:36.024958-05:00bl4th3rsk1t3https://djangosnippets.org/snippets/1480/<p>Renders a view to an email. You need to set all of the required settings for email support.</p>
Freely redistributablemini_render_to_response
2009-04-19T14:02:38.308016-05:00menendezhttps://djangosnippets.org/snippets/1451/<p>You need the mini-detector middleware installed <a href="http://www.iterasi.net/openviewer.aspx?sqrlitid=-e2dfig9w0yrclxaigp-uw">http://www.iterasi.net/openviewer.aspx?sqrlitid=-e2dfig9w0yrclxaigp-uw</a>.</p>
<p>This is a drop in replacement to render_to_response. When using mini_render_to_response it will try to load a version of your template with &#157;mini at the end. For example "home_mini.html" instead of "home.html". If it doesn't find the _mini version it falls back …</p>
Freely redistributableRender specific blocks from templates (useful for AJAX, alternative)
2008-08-04T18:17:47.429198-05:00zbyte64https://djangosnippets.org/snippets/942/<p>Special thanks to the author of snippet 769 who provided most of the code for this snippet. </p>
<p>Major differences:</p>
<p>1.Simpler/better handling of "extends" block tag
2.Searches If/Else blocks
3.Less code
4.Allow list of templates to be passed which is closer to the behavior of render_to_response</p>
Freely redistributableRender (with RequestContext)
2008-07-27T14:43:58.138956-05:00alcideshttps://djangosnippets.org/snippets/919/<p>In order to context_processors work, you need to use the RequestContext instead of Context.</p>
<p>This is a shortcut I use.</p>
Freely redistributableRender specific blocks from templates (useful for AJAX)
2008-05-22T14:48:23.080400-05:00sciyoshihttps://djangosnippets.org/snippets/769/<p>Allows getting the rendered content of a specific block tag. Useful if you want to send just a part of a template back for an AJAX request. Works for arbitrary template inheritance, even if a block is defined in the child template but not in the parent.</p>
<p>Example:</p>
<p>In <code>test1.html …</code></p>
Freely redistributableRender to file
2008-04-08T18:18:07.736766-05:00jacobianhttps://djangosnippets.org/snippets/689/<p>As a demo, I was asked to write a <code>render_to_file()</code> function to load a template and render it to a file. Turns out it's amazingly easy, and I think it's a neat trick to have in your bag of tools.</p>
Freely redistributabledjango_template decorator
2008-02-13T03:28:22.856830-06:00fredd4https://djangosnippets.org/snippets/596/<p>Easy way to caching template.</p>
<p>Very simple usage:</p>
<pre><code> @django_template("my_site.html")
def master_home(request):
variables = { 'title' : "Hello World!" }
return variables
</code></pre>
Freely redistributableRenderer decorator
2007-11-28T07:29:41.126429-06:00GaretJaxhttps://djangosnippets.org/snippets/489/<p>You can use this as a decorator for your views, this way you can return a simple dictionary and the decorator will do the rest.</p>
<p><strong>@TODO:</strong> Automatically set the template based on the app/view request</p>
Freely redistributableRender dynamically assigned fields in a template
2007-03-05T07:44:38.226982-06:00rubichttps://djangosnippets.org/snippets/82/<p><strong>Problem:</strong> You want to render an arbitrary number of fields assigned dynamically, as in <a href="http://www.djangosnippets.org/snippets/27/">snippet #27</a>, but using multiple <code>if</code> statements in a template would be tedious.</p>
<p><strong>Solution:</strong> newforms BoundField</p>
<p>The example demonstrates a form with medication fields. We don't know in advance how many meds will be prescribed …</p>
Freely redistributable