Login

Snippets by amr-mostafa

Snippet List

Quickly check templates while sketching them out

This a small but very handy view that gives you a convenient direct access to your templates. Now suppose you saved the snippet under `misc.py`, it's critical to add this snippet (or a similar one, once you get the idea) to your `urls.py`: if settings.DEBUG: # Direct Templates urlpatterns += patterns('misc', (r'^template/(?P<path>.*)$', 'direct_to_template', {'template': '%(path)s'}), ) Now you are able to access any of your templates, in different directories by specifying their path after `template/`. e.g., http://example.com/template/news/index.html Of course you can change it as you want, you can also add other values to the dict argument, the only required key is `'template'`. The whole dict is made available in the template as a context. All GET parameters are made available in the template too. So `http://example.com/template/news/index.html?title=Testing Title` will make the `{{ title }}` var available in your template. So you can substitute basic variables quickly. This is was inspired by [django.views.generic.simple.direct_to_template](http://www.djangoproject.com/documentation/generic_views/#django-views-generic-simple-direct-to-template)

  • template
  • view
  • generic
Read More

Handy tag for generating URLs to media files

Returns an absolute URL pointing to the given media file. The first argument is the path to the file starting from MEDIA_ROOT. If the file doesn't exist, empty string '' is returned. For example if you have the following in your settings: MEDIA_URL = 'http://media.example.com' then in your template you can get the URL for css/mystyle.css like this: {% media 'css/mystyle.css' %} This URL will be returned: http://media.example.com/css/style.css.

  • template
  • tag
  • media
Read More

amr-mostafa has posted 2 snippets.