- In your template:
- put
{% csrf_token %}
inside your<form>
eg:<form> {% csrf_token %} ... </form>
- put
- In your view:
from django.template import RequestContext
- pass
context_instance=RequestContext(request, {})
torender_to_response
Category Archives: django
I put Martin’s django-captcha on github
jsonify: Django custom template filter
This template filter converts the filtered variable to json. I added comment to that snippet to:
1. Pass a kwarg cls=ModelJSONEncoder
to simplejson.dumps
to get handling of django.db.models.Model objects (get ModelJSONEncoder here). And as sk1p pointed out, you’ll also get handling of datetime objects and decimals for free.
2. Put jsonify.is_safe=True
after register.filter
so you don’t need to do {% autoescape off %}
or |safe
every time you use jsonify.
sqlite3.OperationalError: unable to open database file
Check your settings.py DATABASE_NAME, ensure that:
– The path is absolute path, don’t use ~ $HOME etc, and
– The path exists, and
– The database file exists (if it doesn’t, use manage.py syncdb), and
– Webserver has read and write access to the file, and
– Webserver has read and write access to the directory containing the file.
Anything else?
Django captcha app
Thousand thanks to Martin Winkler for making an ultra-useful captcha app for django here. It’s super-easy to use although if you want to use it with Django 1.1 you need to modify it first.
I made the patch for Django 1.1 compatibility, which can be downloaded here.
I also made some other patches to remove md5 deprecation warning (here) and to fix a font-loading bug if you use the app with Subversion/git/some other VCS (here).
UPDATE: It seems that Martin’s site does no longer exist, so I put the Martin’s originals along with all my patches on github.