Template Tag for Retrieving Settings
Useage: `{% load setting %}` `{% setting DEBUG %}` or... `{% setting MEDIA_ROOT %}` You get the gist.
- template
- tag
- settings
Useage: `{% load setting %}` `{% setting DEBUG %}` or... `{% setting MEDIA_ROOT %}` You get the gist.
It's cheap, hackish, and dirty, but it works. \\o/ Lines 19 & 20 are what you should edit.
This middleware will add a log of the SQL queries executed at the bottom of every page. You can (should) use BeautifulSoup to place this in a specific location. Note: If you serve non-html content, it would be wise to do a mimetype check.
This will perform a regular expression search/replace on a string in your template. `{% load replace %}` `{{ mystring|replace:"/l(u+)pin/m\1gen" }}` If: `mystring = 'lupin, luuuuuupin, and luuuuuuuuuuuuupin are lè pwn'` then it will return: `mugen, muuuuuugen, and muuuuuuuuuuuuugen are lè pwn` The argument is in the following format: [delim char]regexp search[delim char]regexp replace
`foo = dynamic_import ( 'rawr.i.am.a.lion' )` Will import `lion` from `rawr.i.am.a` and return it. (This isn't really Django specific) Props to Crast for the original.
This function takes a string (most likely from a template), searches it for `<code>[...]</code>`, highlights it with Pygments, and returns the entire thing back, as a string. (Note: the `<code>[...]</code>` must have a class corresponding to the language inside. If it lacks the class, then it's silently ignored.)
Put inside `mysite/templatetags/getattr.py` Add `mysite` to your `INSTALLED_APPS` In your template: {% load getattr %} {{ myobject|getattr:"theattr,default value" }} Thanks to pterk for optimizations! \\o/
UPDATED: This now supports an argument for the initial header level. This is a modified version of `django.contrib.markup` that allows you to highlight code via [pygments](http://pygments.pocoo.org/). The code block can be used as: `Here's a paragraph, and a code example: .. code:: language *insert code here* continue with your normal document.` Setup: Insert the snippet into `mysite/templatetags/rest.py`, then add `mysite` to your installed apps in `settings.py`. In your template, `{% load rest %}` and `{{ mycontent|rest }}`.
A very common field in forms is the `<textarea>`, but `newforms` has no such field. Instead, you must use a dummy field (such as `newforms.CharField`) and use the `newforms.widgets.Textarea()` widget to render a textarea.
joshua has posted 9 snippets.