26👍
use tag : http://docs.djangoproject.com/en/dev/ref/templates/builtins/#autoescape
{% autoescape off %}{{ variable }}{% endautoescape %}
- Fabric – sudo -u
- Django request.user.is_authenticated is always true?
- Error loading psycopg2 module: Library not loaded: libpq.5.dylib
- No connection could be made because the target machine actively refused it (Django)
2👍
For simple HTML formatting, use <p>{{something}}</p>
. And the Javascript way is,
<script type="text/javascript">
var variable = "<p>{{something}}</p>";
document.write(variable);
</script>
If that {{something}}
itself contains the HTML tags, then {{something|safe}}
itself should work unless you have {% autoescape on %}
. For more filtering and formatting refer Built-in template tags and filters.
0👍
I think another approach for this is to use the firstof
tag:
Note that the variables included in the firstof tag will not be escaped. This is because template tags do not escape their content. Any HTML or Javascript code contained in the printed variable will be rendered as-is, which could potentially lead to security issues. If you need to escape the variables in the firstof tag, you must do so explicitly
{% firstof variable %}
- How to mock chained function calls in python?
- Should I use google-app-engine-django or app-engine-patch or neither or something else?
- Django: python manage.py runserver gives RuntimeError: maximum recursion depth exceeded in cmp