django-templates

"Last" tag not working

I have a queryset of "promotion" events which are rendered in a template. Each of these promotions also have 1 or more appointments. What I want to do is display the dates of the first and last appointments. So far, using the "first" tag works. However, using the "last" tag causes: TemplateSyntaxError Exception Value: Caught an e...

WTForms extension for Django templates not working

I feel like I am missing something really obvious. I'm trying to use the WTForms template extensions with Django. I have a project on my development server which is working great (IE the extensions are working properly) but when I put it out on a test server, suddenly they are broken. Both servers have the same versions of Python, Dja...

Django template inclusion

The template inheritance page on the django site doesn't really solve my problem (Django 1.2). My base page looks like: ... <div class="grid_12" id="content"> {% block content %}{% endblock %} </div> ... {% block javascript %}{% endblock %} I have another template that defines content for these: {% block content %} animated si...

Conditionally including content into Django 1.2 templates

How can I include with Django what Symfony calls 'components' - bits of logic and a template that's not associated with the content of the current page? For example I want to include a sidebar that displays a list of the top 10 articles on the site. It should always be displayed if the user is looking at either an 'article' page or a 'v...

Repopulate django form

Wanted effect is passing the id to the request handler and populating the form with that entity. How doable is it with a template? Here are my form, request handler and template class AForm(djangoforms.ModelForm): text = forms.CharField(widget=forms.Textarea(attrs={'rows':'11','cols':'70','class':'foo'}),label=_("content").capitaliz...

Template engine similar to the Django

I search template engine for PHP that's almost similar to the Django template. ...

djnago not rendering css style on text stored in database

I format text with java script and after that I store it in database, but when i get this text from database and display in a template then django do not apply css format tags , and just display them as text instead of apply. Please tell what is the problem ? ...

Creating a list on the fly in a Django template

I don't know whether it's possible, but I'd like to be able to write something like the following: {% with var1 var2 var3 as some_list %} {{ some_list|maximum }} {% endwith %} Creating a list on the fly from an arbitrary number of template variables and/or literals seems useful, so I'm hopeful that I've overlooked something simple...

django template inheritance and context

I am reading the definitive guide to django and am in Chapter 4 on template inheritance. It seems that I am not doing something as elegant as should be possible as I am having to duplicate some code for the context to appear when calling the child view. Here is the code in views.py: def homepage(request): current_date = datetime.da...

How do I use a Django custom template tag in a template?

I’ve written a custom template tag: def mytag(para): return something In my template I am getting a value {{value}}. Now I am using {{value|mytag}} to apply the tag to the value, and it is throwing a syntax error. ...

Why doesn't Django produce locale files from template files in another directory?

Version info: Django version 1.3 pre-alpha SVN-13858 Ubuntu GNU/Linux 10.10 I'm totally new to i18n and l10n in Django and currently I'm trying to make my Django project available in Dutch (in addition to its default language: English). I tried to apply the instructions given at http://docs.djangoproject.com/en/dev/howto/i18n/ and ht...

Django template variable value to string literal comparison fails

I have the following code in my template that supposed to compare the value of watchinstance.shift, which can be either "DAY" or "NIGHT", to a literal string "DAY". The comparisson always fails. {% for watchinstance in watchinstance_list %} {% if watchinstance.shift == "DAY" %} <p>shift is DAY</p> {% endif %} {% endfor %...

Django: ModelForm confusion

I am trying to display a bound ModelForm in my template. Here the the code from the view: assessment = Assessment.objects.get(slug=slug) form = AssessmentForm(assessment) But when I then pull up the template, it is empty except for the submit button. When I try to debug with PDB, I get: (Pdb) form.data <Assessment: Alaska - Coastal...

How do I resuse HTML snippets in a django view

I am working on a django project (my first), and in one of my views, I have a sophisticated html snippet with JS weaved within it. I would like to reuse this "component" somewhere else in the same view. Is there a way of achieving this? Please let me know if this design is faulty to begin with? ...

Filtering Model formsets

First try at playing with model formsets with django and was wondering how to filter by the logged in user. The view below renders a form with all the profiles when I only want them to list one (the user's one). def create_profile(request): ProfileFormSet = modelformset_factory(Profile) if request.method == 'POST': formset...

Django Many to Many in template

This is my template tag in a forloop {{ product.feature_set.all.1.value }} i want to change the number 1 to the forloop.counter. is this posible? like: {{ product.feature_set.all.forloop.counter.value }} It does not work like that, but is there a way to do this? ...

Summarizing inside a Django template

I have the following template in django, i want to get the totals of the last 2 columns for each of my document objects {% for documento in documentos %} {% for cuenta in documento.cuentasxdocumento_set.all %} <tr {% cycle 'class="gray"' '' %} > {% if forloop.first %} <td>{{ documento.fecha_cr...

Django jQuery update fragment

Hi. I have a menu which shows certain information such as message_count, notifcation_count from django, and also a user profile that makes use of a load of jquery ajax functions to get information when a user clicks a url reference. one of these reference relates to a users messages that he can view in his profile, without being redire...

Two foreign keys and a value in django template

I am a newbie to django, so the question might be dumb, but please feel free to teach me the right way if you know it. I tried googling the issue, but I am still at loss. Here's my problem: I have a class in my model that has two foreign keys: class X(models.Model): name = models.CharField(max_length=30) def __unicode__(self): ...

Displaying reverse many-to-many in Django Templates

I'm in the midst of creating an alarm/notification system for a small Sales CRM app. I have a Lead_Contact model that is used to store a client's name, address, etc. as well as a Contact_Notifier models that is being used to keep track of when a client was first contacted, the last contact, and when we are going to next contact them. F...