Login

All snippets written in HTML/template

Snippet List

Image inlining template tag example

The example of the Image inlining template tag lib which inline images in the browser instead of making an Http request. The lib is available at : [http://djangosnippets.org/snippets/2268/](http://djangosnippets.org/snippets/2268/)

  • tag
  • image
  • templatetag
  • base64
Read More

Admin Word Count

I'm on my own personal writing challenge (see 750words.com for inspiration). I needed a way to get a dynamic word count, so I threw this together. Tied into django-basic-blog easily.

  • jquery
  • change-form
  • word-count
Read More

Django csrf_token Template Tag Fix

If you currently use `{% csrf_token %}`, you will notice it prints a hidden div, and an xHTML input tag. What if you don't want that hidden div, and/or you want your page to validate with HTML and not xHTML. This snippet returns only the csrf token itself, and none of the related HTML code. You can use it like this. `<input type="hidden" name="csrfmiddlewaretoken" value="{% with csrf_token as csrf_token_clean %}{{ csrf_token_clean }}{% endwith %}" >`

  • csrf_token
  • csrf_token_clean
Read More

Use JQuery Calendar in ModelForm

The important code really is just setting up the base site to use jquery and then using the javascript function to show the calendar on a widget with the .vDateField class set. The DateField modeltype automatically gets the css class .vDateField when using ModelForms.

  • jquery
  • calendar
  • widget
  • modelform
Read More

Output sql_queries in Firebug console when in debug mode

Add this code to the end of the `<body>` of your main template and it will print out all your SQL queries with timings in the Firebug console. This uses the "django.core.context_processors.debug" template context processor, which requires that DEBUG=True and that your IP address is listed in INTERNAL_IPS.

  • sql
  • debug
  • console
  • firebug
  • sql_queries
Read More

Gallerific template for django-photologue

Template to make a galleriffic gallery for django photologue. Uses the settings from this demo http://www.twospy.com/galleriffic/example-2.html This is now the default template for the django-cms photologue plugin http://www.django-cms.org/en/extensions/cmsplugin-photologue/detail/

  • photologue
  • photo-gallery
  • django-cms
Read More

Drop in dynamic formsets in admin

A very plugable way to get Stanislaus jquery dynamic formset working in the admin with adding just one template. Add the following to templates/admin/APP/MODEL/change_form.html and also update the MODEL in the prefix setting. Thanks Stanislaus [http://elo80ka.wordpress.com/2009/10/10/jquery-plugin-django-dynamic-formset/](http://elo80ka.wordpress.com/2009/10/10/jquery-plugin-django-dynamic-formset/) [http://go2.wordpress.com/?id=725X1342&site=elo80ka.wordpress.com&url=http%3A%2F%2Fcode.google.com%2Fp%2Fdjango-dynamic-formset%2F](http://go2.wordpress.com/?id=725X1342&site=elo80ka.wordpress.com&url=http%3A%2F%2Fcode.google.com%2Fp%2Fdjango-dynamic-formset%2F) [http://www.djangosnippets.org/snippets/1389/](http://www.djangosnippets.org/snippets/1389/)

  • dynamic
  • admin
  • jquery
  • inlines
  • formsets
Read More

Front end admin toolbar

This snippet will monkeypatch `django.db.models.Model` to include 7 new methods: * `get_verbose_name` Because you can't access model._meta from templates * `get_verbose_name_plural` * `get_admin_change_url` * `get_admin_delete_url` * `get_admin_history_url` * `get_admin_changelist_url` * `get_admin_add_url` This snippet also gives you the template code to paste to your `base.html` so every front end model instance view of your site will show an admin toolbar for logged in users that have admin access.

  • admin
  • toolbar
Read More

Accordion changelist admin

Allows you to hide the filters in the pages of lists of admin. Very useful when filters hide one or more columns. Add this code after the block "extrastyle"

  • admin
  • changelist
Read More

Dom ID

Helper for identifing records in views similiar to rails dom_id helper.

  • templatetag
  • templatefilter
  • dom_id
Read More

language switcher in admin

you have a multilingual site and need to change languages in admin. Previously this was easy in the site itself and more difficult in admin. Now it is dead easy. Set up your languages in settings.py. Make a directory called 'admin' in your templates directory, copy ~/django/contrib/admin/templates/base.html to that directory. Add the following code (below breadcrumbs is a good place) this will give you a switcher for all installed languages. You would need to refresh the browser on changing the language.

  • admin
  • i18n
Read More

78 snippets posted so far.