Hello,
I am wondering if someone can help me figure out the best approach to the following problem. I'm building a web application which uses Django templating to construct its web UI component. There are a number of common HTML elements such as the header / footer, HTML head, masthead etc. I'd like to code these once and "include/co...
I am running Django trunk and have template Autoescaping on (default). Do I need to pass template URLs to the URLENCODE filter, or does Autoescape take care of that automatically? The Django docs aren't clear.
Django docs say this about Autoescape:
When auto-escaping is in effect, all variable content has HTML escaping applied to it...
After reading the Jinja2 documentation, I'm interested in employing it in future Django projects. However, I'm wondering if anyone has encountered any drawbacks or gotchas when using Jinja2 templates with Django? If so, how did you work around them?
I wouldn't mind hearing about positive experiences either, just to get a good cross se...
Here's my custom filter:
from django import template
register = template.Library()
@register.filter
def replace(value, cherche, remplacement):
return value.replace(cherche, remplacement)
and here are the ways I tried using it in my template file that resulted in an error:
{{ attr.name|replace:"_"," " }}
{{ attr.name|replace:"_"...
I'm storing some additional per-user information using the AUTH_PROFILE_MODULE.
We can access the user in a Django template using {{ request.user }} but how do we access fields in the profile since the profile is only accessible via a function user.get_profile() ?
Is it really required to explicitly pass the profile into the template e...
I have some stuff in settings.py that I'd like to be able to access from a template, but I can't figure out how to do it. I already tried
{{CONSTANT_NAME}}
but that doesn't seem to work. Is this possible?
...
So, I have a decimalfield that can be 3 different values. In my view,
I pass in a dictionary of values that contains the appropriate decimal
values as keys.
{% for item in booklist %}
{% for key, value in numvec.items %}
{{item.number}}
{% ifequals item.number {{key}} %}
{{value}}
{% end...
Variations of this question have been asked, but I'm still unable to get my stylesheets to load correctly when my templates are rendered.
I'm attempting to serve static media from the Django process during development - which is strongly discouraged in production, I'm aware. I'll post my configuration and my template, and hopefully some...
Hi,
Django templates offer the builtin tag cycle for alternating between several values at different points in a template (or for loop in a template) but this tag does not reset when it is accessed in a scope outside of the cycles definition. I.e., if you have two or more lists in your template, the rows of all of which you'd like to u...
I've got a CMS that takes some dynamic content and renders it using a standard template. However I am now using template tags in the dynamic content itself so I have to do a render_to_string and then pass the results of that as a context variable to render_to_response. This seems wasteful.
What's a better way to do this?
...
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#regroup
I can think of a few ways of doing it with loops but I'd particularly like to know if there is a neat one-liner.
...
I'm having problems using {% ifequal s1 "some text" %} to compare strings with extended characters in Django templates. When string s1 contains ascii characters >127, I get exceptions in the template rendering. What am I doing wrong? I'm using UTF-8 coding throughout the rest of application in both the data, templates and Python code wit...
I want to use the same {% block %} twice in the same django template. I want this block to appear more than once in my base template:
# base.html
<html>
<head>
<title>{% block title %}My Cool Website{% endblock %}</title>
</head>
<body>
<h1>{% block title %}My Cool Website{% endblock %}</h1>
</body>
</htm...
I happened to stumble across HAML, an interesting and beautiful way to mark up contents and write templates for HTML.
Since I use Python and Django for my web developing need, I would like to see if there is a Python implementation of HAML (or some similar concepts -- need not be exactly identical) that can be used to replace the Django...
I am writing out a table using just the template system in Django, and it is not showing the border around empty table cells.
No problem I thought - I've solved this problem before. I put   in any cell that was to be left empty. Django kindly converted the ampersand to & so that I have &nbsp in the empty cells, and it shows ...
I'm working on a little django app for reserving prints of paintings.
Customers go to this ordering page, fill out some information (name, email, dedication, etc), pick the print number they want to reserve, and click order. On clicking, I have my django code storing all the customer information in a new OrderInfo object, and it call...
I am trying to assign some javascript variables in a Django template.
I am having a problem where the values I am assigning are being written to the page properly (I can see them in the page source), but still come up as null.
I am doing this:
<script type="text/javascript">
var coords = [];
{% for i in item_list %}
coords.pus...
I have the following code in one of my Django templates that I want to refactor:
{% ifequal sort_type "set" %}
{% regroup cards by set as grouped %}
{% endifequal %}
{% ifequal sort_type "rarity" %}
{% regroup cards by rarity as grouped %}
{% endifequal %}
It does work, but it's really ugly and I want to make it more like this:
...
Help please with a django custom tag. Analize it please!
Idea:
In any template (parent or child), we installing a tag {{ telepoint "head" }}, with a name, such putters could be more than one.
At other side, we have block
{{ teleputter "head" "unique-name" }} some html {{ teleputterend }}
Content of this block goes to telepoint wit...
I would like to do:
{% if appnav %}
<hr />
<div id="appnav">
<ul class="tabs">
{% block appnav %}{% endblock %}
</ul>
</div>
{% endif %}
...however, testing for the present use of a block by templates further down the inheritance chain doest seem to work.
Is there some other conditional that might do this?
...