runserver with extra development tools:
1. interactive debugger that pops up automatically if an exception occurs, courtesy of [Werkzeug](http://werkzeug.pocoo.org/documentation/dev/debug.html#using-the-debugger)
2. logging of print statements directly into HTML (div float), courtesy of [Paste](http://pythonpaste.org/modules/debug.prints.html).
Credits: [piranha.org.ua](http://piranha.org.ua/)
Django Pagination Template Tag that allows unlimited customization to the current Django Pagination.
Automatically creates template variables that can be used to display the pagination in any format that you can desire such as
Previous 1 2 3 [ 4 ] 5 6 7 Next
First Previous 12 14 15 16 17 [ 18 ] 19 20 22 25 Next Last
Showing 25 of 80 Results
First Page 23 27 30 33 [ 36 ] 38 41 44 50 Next Last
This is a simple URI Querystring generator that can be used with Django for generating URI Querystring and preserving the current
Currently working to port into a template tag to allow
{% urlgen page|5 %} {% urlgen page 5 %} {% urlgen page,5 %}
OR
{% urlgen sort name display all %} etc..
Simple decorator to render an html template or return a json response. The view must return a dict object.
Usage example:
@render('page.html')
def a_view(request):
#do something
return {'key': 'value'}
This decorator is to make it's decorated function to commit the transaction on success (rollback otherwise) unless the transactions are being already managed.
In Django humanize naturalday filter, you could not get the time part since a programming issue, If you apply it like:
{% load humanize %}
{{ response.date_submitted|naturalday:"Y/n/j H:i" }}
You can get 'today', 'yesterday', 'tomorrow' or empty, but you can not get such as '2009/9/10 11:56'
So I change it like above code. Now you can get 'today', 'yesterday', 'tomorrow' or '2009/9/10 11:56'
If you want anonymous visitors to your site, or parts of your site to be authenticated as real users so that you can treat them as such in your views and models, use this snippet. Add the above AuthenticationBackendAnonymous middleware into AUTHENTICATION_BACKENDS in your settings.py and use the snippet anonymous_or_real(request) in your views, which returns a user. Comment out the bit where it creates a profile if you are not using profiles.
This trick is for caching a view only if it passes some condition, for example, if there are more than zero items in a list. The same methodology could be used for conditional applying of other decorators.
Use HTTP Authorization to log in to django site.
If you use the FORCE_HTTP_AUTH=True in your settings.py, then ONLY Http Auth will be used, if you don't then either http auth or django's session-based auth will be used. This assumes that the regular auth middleware is already installed.
If you provide a HTTP_AUTH_REALM in your settings, that will be used as the realm for the challenge.
Having both a decorator and a middleware means that for site-wide http auth, you only need to specify it once, but the same code can be used as a decorator if you want part of your site protected using htty basic auth, and the other bits freely visible.
Of course, since this is basic auth, then you need to make sure your site is running under SSL (HTTPS), else your users passwords are effectively transmitted in the clear.
Based loosely on [Eric's middleware](http://ericholscher.com/blog/2009/sep/5/debugging-django-production-revisited/), this middleware will show the technical 500 page (which you'd get if DEBUG == True) to any user who is (1) superuser and (2) a member of the settings.TECHNICAL_500_GROUP_NAME group. (If no setting exists, 'Technical Errors' is the presumed group name.
I agreed with the comments that caching should be unnecessary given the (presumptive) edge case of exception + superuser. Assuming you don't have tons of superusers, this code is a good bit simpler.