This seems silly, but I don't understand how Django Templates access nested data in Contexts. I can access the values of dictionaries nested in the context data structure with the . notation -- {{ aDictionary.i_am_a_key }} works fine. But if I try to iterate over a list of keys and get their value from that same dictionary, I get nothi...
My Django templates use a lot of related stuff: images, style sheets, etc.
Where should I put these file, or how should I refer to them in the template itself?
For now I'm using the development server.
I know it's a really common thing, but I can't really figure it out.
...
Hello everyone
I have templates of this style
project
- main_templates (including nav bar)
-- app1
--- app1_base_template
--- app1_templates
-- app2
--- app2_base_template
--- app2_templates
So when rendering, app2_templates extends app2_base_template which extends main_template.
What I need to do, is have the corresponding nav ite...
I'd like to be able to display additional information like a text label with each row in a Django formset.
Example/usecase:
User picks 5 rows in a model that would he would like some action performed. A popup appears that displays a 5 form formset some additional information (that are model instance methods) based on the 5 rows chosen...
Thanks to a very helpful hint from another question I learned I can limit the amount of values in a list by slicing it in the template as such:
{% for comment in thread.comment_set.all|slice:":3" %}
Now I would like to get the last 3 results of my comments so I figured a simple ":-3" or "-3" would do the trick, alas:
Caught an except...
The master template in my Django app looks like this:
{% block parent %}
Some text...
{% block child %}
Default content here...
{% endblock child %}
...some more text
{% endblock parent %}
Now, this template should be overwritten in a way that the child block is changed:
{% extends "master.html" %}
{% block c...
If I want some text to appear literally in a Django template, e.g.
{{Image.jpg|title}}
and I want that text to be output (not interpretated) in the HTML, how do I do so?
...
I am trying to present a dictionary from my view.py at the HTML template such as:
test = { 'works': True, 'this fails':False }
and in the template:
This works without a problem:
{{ test.works }}
But a dictionary key that is having an empty space between words such as 'this fails' doesn't work:
{{ test.this fails }}
I get this e...
I have been developing some Django app and there's some duplicated code for different Models. I'd like to create a generic table template and pass the Model class, a list of model instances, and Form classes to it so it can render the page and generate the forms to add/delete elements. Then create some generic add/delete views to work wi...
In my Model I define choices along the lines of:
LANG_CHOICES = (
("Englisch", (
(u"en-gb", u"England"),
(u"en-us", u"United States of America"),
), )
The field is defined as:
lang_source = models.CharField(max_length=5, choices=LANG_CHOICES, default="en-gb")
Naturally, in my template I'd want to display the...
To the risk of being closed as duplicate (I can't really find it...) I have the following question. I am sure it's either under my nose, or not possible, but I prefer to ask.
Is it possible to bind to multiple, shorter variable names in django? I know the existence of with, but with assumes you open a block. I would like to bind three o...
If you change your urls.py or you stupidly write some template code that refers to a URL that ultimately doesn't reverse to a URL you get the infamous:
NoReverseMatch: Reverse for '<name>' with arguments 'xxx' and keyword arguments '{xxx}' not found.
Is there a way to have the line in the template file included in the error?
...
I'm a bit compulsive about having clean, readable and perfectly indented HTML. With Django’s template engine I almost have been able to achieve this with the exception of block text, or rather HTML generated by TinyMCE through the admin panel. The closest I could get is using the wordwrap filter; however this tag does not take any argume...
According to The Django Book, Django's templating system supports nested dot lookups:
Dot lookups can be nested multiple levels deep. For instance, the following example uses {{ person.name.upper }}, which translates into a dictionary lookup (person['name']), then a method call (upper()): '{{ person.name.upper }} is {{ person.age }}...
I'm on my first Django blog and when trying to get the posts by year, month and day, using the built-in generic view from Django, but I don't get proper results. (Sorry for my non-professional first question.. if someone knows what is the appropriate question, please let me know)
Well, I think it's better to show you my configuration to...
I'm building a Blog in Django (using Generic Views) and I use the same template for both my date based and list detail views. I'm trying to setup pagination, but I want to do so with URL patterns rather than using an ugly ?page=1 url suffix.
The problem is in the actual html template, I cannot find a way to determine which view was used...
Hi,
I want to create dynamic menus according to user permissions. As was already discussed here and by the the documentation itself, I know that I can achieve this in the templates using the following snippet:
{% if perms.polls.can_vote %}
<li>
<a href="/polls/vote">Vote</a>
</li>
{% endif %}
But the problem is that f...
Hello, I have a product list that put 3 products on a row and clears the row and adds another 3, this works fine everywhere but IE6, i know that adding <div> around each group of 3 products will solve this is the template file at the moment
{% for product in category.products.all %}
<div class="{% cycle 'clear' '' '' %}">
<a ...
The following code in one of my views returns unescaped html string which cannot be parsed in frontend since it is an Ajax request.
return render_to_response(template_name, {
'form': form,
redirect_field_name: redirect_to,
'site': current_site,
'site_name': current_site.name,
}, context_instance=Reque...
I am obtaining the path of template using
paymenthtml = os.path.join(os.path.dirname(__file__), 'template\\payment.html')
and calling it in another application where
paymenthtml gets copied to payment_template
return render_to_response(self.payment_template, self.context, RequestContext(self.request))
But I get error
Templ...