Login

All snippets written in HTML/template

Snippet List

very archive template

I tried to think of a way to use generic views to show all my blog posts on one page organized chronologically with each post title under one month name and all the month names under one year name. Like so: ` 2009 October My last example blog entry Entry even before the last one First of October September Only one entry in Sept. 2008 December It is cold in December First posting of my blog ` I could not think of a way to do this using generic views, before I wrote a view and some template logic that does. The view code is here: [http://www.djangosnippets.org/snippets/1766/](http://www.djangosnippets.org/snippets/1766/) Any suggestions for design patterns are greatly appreciated.

  • archive
  • blog-entry
Read More

Search DjangoSnippets with Firefox

You have to put this code in your *searchengines* Firefox folder in a file called **djangosnippets.xml** After restarting Firefox, you will be able to seek DjangoSnippets very easily. I also create a favicon.ico since djangosnippets.org didn't have one ... Path example : /usr/lib/iceweasel/searchplugins/djangosnippets.xml

  • xml
  • firefox
  • djangosnippets
  • searchengine
Read More

Active class for navigation link

Active class for navigation link {% navclass default current url %} First argument is the default class and second is the current class Third argument is the url name(s) of the page example: <a class="{% navclass leftnav curentnav name1,name2 %}" href="/about/">

  • css
  • style
  • navigation
  • active
Read More

Printing inline formsets as UL / P

By default all forms created using inlineformset_factory are displayed as tables (because there is only a .as_table method) and there are no .as_p or .as_ul methods in them, so you need to do that by hand.

  • django
  • formset
  • inline
  • not-django-admin
Read More

email rendered via javascript (trick spam crawlers)

The proper looking email links rendered to the browser are not in the source code that way, and are rendered by javascript, so robots can't extract it. Its a trick way to have the email displayed properly without getting spamed as a result. Unless the robots are getting smarter, this has worked for me thus far.

  • template
  • email
Read More

improved sortby template tag

Variation on dictsort using attribute access. Nested attributes can be used, like, "obj.attr.attr_attr" Example usage: {% for entry in entries|sortby:'category.title' %} Based on [1609](http://www.djangosnippets.org/snippets/1609/)

  • template
  • tag
  • dictsort
Read More

entity encoded email-address

entity encoded string for a somewhat safer email-address. this filter encodes strings to numeric entities, almost every standard-browsers decodes the entities and display them the right way. needless to say that bots are smart, so this is not a 100% guaranteed spam prevention.

  • email
  • spam
  • prevention
Read More

Making a django inline (model) formset really tabular

As there is no straight way to re-produce the real tabular inline formsets you get in django-admin, here is how this template has to look like if you do it form your own formsets generated from formset factories.

  • template
  • form
  • modelform
  • formset
  • inline
Read More
Author: fnl
  • 5
  • 6

Template range filter

Easy to use range filter. Just in case you have to use a "clean" for loop in the template. Inspired by [Template range tag](http://www.djangosnippets.org/snippets/779/) Copy the file to your templatetags and load them. [Django doc | Custom template tags and filters](http://docs.djangoproject.com/en/dev/howto/custom-template-tags/)

  • template
  • filter
  • range
Read More

getting the related entries with a templatetag using django-tagging

Django tagging by default doesn't provide a templatetag to get the related objects for another object. Even though this is implemented as a model. Still, one can use the existing templatetags to achieve the same outcome. Of course, writing a custom templatetag would be more efficient in terms of database access.

  • templatetag
  • tagging
  • related
  • django-tagging
Read More
Author: V
  • 0
  • 2

78 snippets posted so far.