Simple REST APIs
This is how I tend to roll simple REST APIs. It's by no means as full-featured as something like Piston, but it's simple, clean, and it works.
- rest
This is how I tend to roll simple REST APIs. It's by no means as full-featured as something like Piston, but it's simple, clean, and it works.
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>`
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.
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.
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 a mixin that can be used to render forms from predefined templates instead of using .as_table / .as_p / .as_ul
Add this to your middleware to log errors to the Apache error log when running under mod_wsgi.
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
Handles navigation item selection. See the `nav` docstring for details.
please delete this, a snippet got posted twice accidentally
Example: class NewsAdmin(InitialFieldsMixin, admin.ModelAdmin): initial = {'author_name': lambda self, request, obj, **kwargs: request.user}
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/">
3110 snippets posted so far.