Snippet List
Sometimes, when you're working on improving one specific aspect of your site, it's easier to browse your code by type than by application. E.g. you want quick access to all admin.py files because you're improving or customizing your admin site across the board and not for a specific app. This little management command adds a shortcuts dir to your project root that contains a bunch of symlinks to your code, organized in subdirs by type of code.
You'll have to put this in `/management/commands/make_shortcuts.py` under an app of your choice. Usage: `python manage.py make_shortcuts`. Don't forget to ignore the /shortcuts directory in your source code management software.
- shortcut
- utility
- organization
from url_helper import execute, url_
import views
urlpatterns += patterns('',
url(r'^(?P<urls>.*)', execute, {'views': views}),
)
url_(r’/space/:username/:tag/’, views.url_),
equal
url(r’^space/(?P[^/]+)/(?P[^/]+)/$’,
Decorator, written for views simplification. Will render dict, returned by view, as context for template, using RequestContext. Additionally you can override template, returning two-tuple (context's dict and template name) instead of just dict.
Usage:
@render_to('my/template.html')
def my_view(request, param):
if param == 'something':
return {'data': 'some_data'}
else:
return {'data': 'some_other_data'}, 'another/template.html'
- render_to_response
- requestcontext
- shortcut
- decorator
- rendering
Sometimes we want to get a queryset or 404, for example, if we're passing our queryset to a subclassed generic view. This is identical to get_list_or_404 but returns a queryset.
- shortcut
- template
- queryset
- get_queryset_or_404
- get_list_or_404
Simplifies using RequestContext in render_to_response.
Simply call the wrapper with request as the first argument, and the rest of the arguments are as normal for render_to_response.
ex: render_response(request, 'foo_list.html', {'foo': Foo.objects.all()})
- render_to_response
- requestcontext
- shortcut
- template
9 snippets posted so far.