Login

All snippets

Snippet List

simple tag-cloud Template Tag

This Template Tag computes the font-size of two given arguments and returns a CSS-encoded string like "font-size: XXpx;", which can be used to format the font-size of link. (The minium font-size must be set with CSS.) Requires two arguments: 1. occurrence of the current tag 2. sum of all occurrences It works great for my tag-cloud. [Source of the logarithmic formula](http://www.php.de/php-fortgeschrittene/44928-tag-cloud-algorithmus-fuer-schriftgroessye.html) **Usage** `<a href="http://www.anything.com" {% cloudify variable.occurrence overall. occurrence_sum %} title="anything">any tag</a>`

  • tag
  • cloud
  • logarithmic
Read More

Twitterfy

Improved version of my snippet #1346. Now works correctly with multiple usernames and hash tags. Both twitter usernames and hashtags are converted into links to twitter profiles and twitter search. Updated, forgot about underscores in usernames.

  • template-filter
  • twitter
  • hash-tag
  • at-reply
Read More

ContentType Form

When working with the ContentType model there are generally two issues. 1. Models are listed in the table but not imported. 2. Unicode only returns model not application so being able to select a a app/model is sometimes difficult when to applications have a model with the same name. This snippet gets a listing of imported models and creates a drop down for selection. I also included a function that uses the returned from to get and save the correct ContentType within the primary model.

  • form
  • contenttype
Read More

Interactive debugger and other Paste niceties

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/)

  • print
  • django
  • debugging
  • paste
  • wsgi
  • werkzeug
Read More

Pagination Template Tag

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

  • pagination
  • custom-pagination
  • django-custom-pagination
  • customize-pagination-django
  • pagination-templatetag
Read More

Django Uri Param Generator

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..

  • pagination
  • url
  • uri
  • djangourl
Read More

Render Decorator

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'}

  • render
  • decorator
Read More

TemplateForm

This a mixin that can be used to render forms from predefined templates instead of using .as_table / .as_p / .as_ul

  • template
  • form
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

3109 snippets posted so far.