Login

Tag "safe"

Snippet List

Safe template decorator

A decorator that restricts the tags and filters available to template loading and parsing within a function. This is mainly meant to be used when granting users the power of the DTL. You obviously don't want users to be able to do things that could be potentially malicious. The {% ssi %} tag, for example, could be used to display sensitive data if improperly configured. {% load %} gives them access to all the unlimited python code you wrote in your templatetags. {% load sudo %}{% sudo rm -rf / %} o_0 Note that the "load" tag (among others) is not listed in the default tag whitelist. If you parse a template (however indirectly) in a function decorated with this, unlisted builtin tags will behave like undefined tags (ie, they will result in a TemplateSyntaxError). Since {% load %} is not whitelisted, you may want to include some custom tags or filters as "builtins" for convenience. Simply put the module paths to the libraries to include in the `extra` kwarg or the `extra_libraries` list. Generally, this is not recommended, as these libraries need to be carefully and defensively programmed. **NOTE**: This **does not** do anything about cleaning your rendering context! That's completely up to you! This merely restricts what tags and filters are allowed in the templates. Examples: from django.template.loader import get_template safe_get_template = use_safe_templates(get_template) tmpl = safe_get_template('myapp/some_template.html') from django.template import Template use_safe_templates(Template)('{% load sudo %}') # TemplateSyntaxError: Invalid block tag 'load'

  • template
  • clean
  • safe
  • restrict
Read More

Protect anti robots template tag

This code works like that in the Google Groups you see and when try to see an e-mail and it is like this "[email protected]" with a link to write a captcha code and see the true value. You can use it for anything you want: links, blocks of texts, block of HTML, etc. To use in your template, place the a code like this (remember to load the template tags file with a {% load file_name %} before): {% protectantirobots %} <a href="mailto: {{ office.email }}">{{ office.email }}</a> {% endprotectantirobots %} You can also use **django-plus** application to do this: [http://code.google.com/p/django-plus/](http://code.google.com/p/django-plus/)

  • captcha
  • security
  • protect
  • anti
  • robots
  • safe
Read More

3 snippets posted so far.