django-templates

Finding the Difference in DateTimeFields

I'm trying to find if two DateTimeFields are greater than 2 days difference in a template. Is this possible to do in a template? ...

List variable containing string not getting rendered in Django Template

Hi, I have a list of names, which I render at two different places in a HTML at one place it works fine, the other time it disappears. names= ['a','b','c','d'] In the HTML code I am printing {{names}} this gives me the correct results. When I use the same string in a javascript it stops working but if I replace the variable by...

POSTing forms in Django's admin interface

I'm writing a Django admin action to mass e-mail contacts. The action is defined as follows: def email_selected(self,request,queryset): rep_list = [] for each in queryset: reps = CorporatePerson.objects.filter(company_id = Company.objects.get(name=each.name)) contact_reps = reps.filter(is_contact=True) ...

Django template ifequal tag

I'm using an ifequal tag in my django template inside a loop where atleast one of the items should equal the other at some point in the loop but for some reason it never displays what it should. I was wondering if there are any weird cases that i should know about. I have a list of int city ID's that should be checked as check boxes. so...

Django templates: How do I use a field in the model in a template?

Hi, In this template, <body><p>You searched for: <strong>{{ first }} {{ last }}</strong></p> {% if lawyers %} <p>There are {{ lawyers|length }} schoolmates of <strong>{{ first }} {{ last }}</strong> in the database:</p> <ul> {% for lawyer in lawyers %} <li> {{ lawyer.first }} {{ lawyer.last }} {{ lawyer.firm_na...

Two forms in django templates without conflict

hi, I'm creating a template with two different forms but I have the following problem: when I submit the first one the second is also validated and get validation errors. What can I do to avoid this conflict? Thanks and sorry for my english. ...

In Jinja2, how can I use macros in combination with block tags?

I'm a front end developer, and I've been trying to get a hang on using Jinja2 effectively. I want to tweak a current site so it has multiple base templates using inheritance, it fully uses block tags to substitute content and override it, and uses macros to support passing of arguments. My base template contains this code (edited for si...

Django-pagination: Accessing the page object after using {% autopaginate list %}

I'm using django-pagination to paginate lists for my Django site. At the top of my template, I'm using {% autopaginate projects 10 %} I want to display something like 'Showing 1 - 10 of 52 results'. I know it's easiest to do this with the page objects created by the template tag. The problem is that I don't know how to access it in th...

Django Templates - Changing context for an 'include' template

I have a template that includes several tables. I want to use a sub-template which renders these tables in the same way. I can get it to work for a single table, by setting the context in the view and passing that to the template. But how do you change the data for to render another table for different data? **'myview.py'** from django...

Role of django filters. Filtering or upfront formatting within the view?

I would like to hear your opinion about this. I have a django application, where the data obtained from the model are rough. To make them nicer I have to do some potentially complex, but not much, operation. An example, suppose you have a model where the US state is encoded as two letter codes. In the html rendering, you want to presen...

Calling Python function in Django template

Inside a django template I'm trying to call the split function on one of the template variables and then get the last element, so I did something like this: {{ newsletter.NewsletterPath.split('/').-1 }} Unfortunately, it doesn't like the split. Some might suggest that I do the split in the view, but I'm not sure how to do that because...

Python url template tags giving only part of a absolute url.. ..Must be a lack of sleep..

Hi Guys, I must be suffering from a serious lack of sleep but I am stumped. I can't seem to figure out how to get the {% url %} directive to give me the right url. So let's start with the basics.. urls.py from people.views import employee_detail urlpatterns = patterns("", url(r'/uid/(?P<id>[0-9]+)/$', employee_detail, {'templat...

Django templates: how do I save an item inside a {% for %} loop?

Hello, This application returns schoolmates of lawyers. When a user searches for first name only and there are more than 1 result I leave the query in the form and ask them to enter a last name. But I thought that it would be nicer if the user just clicks to one of the names and search results are returned directly. (at this point the ...

Django - How to pass several arguments to the url template tag

In my urls.py I have: (r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/section/(?P<slug>[-\w]+)/$', 'paper.views.issue_section_detail', {}, 'paper_issue_section_detail' ), and I'm trying to do this in a template: {% url paper_issue_section_detail issue.pub_date.year,issue.pub_date.month,issue.pub_date.day,section_li...

django-grappelli and rare lot of errors

I'm using Django-grappelli in my project, but Django is send me a lot of errors to my email about some files that Django didn't found...but I don't know from where is calling this files...some time files .aspx (??) Here is a image with the error list in my inbox Here is a error detail: Traceback (most recent call last): File "/home...

Google App Engine and Django templates: why do these two cases differ?

I'm new to Python, and I'm using Google App Engine to build a simple blog to help me learn it. I have the following test code: entries = db.Query(Entry).order("-published").get() comments = db.Query(Comment).order("published").get() self.response.out.write(template.render(templatePath + 'test.django.html', { 'entries': e...

django forms error_class

Is there a way to give a form a special error rendering function in the form definition? In the docs under customizing-the-error-list-format it shows how you can give a form a special error rendering function, but it seems like you have to declare it when you instantiate the form, not when you define it. So you can define some ErrorList...

Reading path in templates

Hello, is it any way to read path to current page? For example, I am at www.example.com/foo/bar/ - and I want to read '/foo/bar/'. But, all have to be done in template file without modyficating views. I have to many view files to edit each one. Sorry for my english, hope everyone understand. Cheers. ...

Django templates problem — {% if object|length > 4 %} raises TemplateDoesNotExist: 500.html

Hello, I have the following in my template. {% block content %} {% for album in albumsList %} {% if fotosList %} <div class="photoalbum-wrapper"> <h3>{{ album.title }}</h3> <ul class="photoalbum"> {% for foto in fotosList %}<li>item</li>{% endfor %} ...

Django: where can I find the template that renders the fields of the admin page?

Hi everybody, I want to change the shape of some fields showed in the admin site. I found that the template that manage everything is change_form.html with fieldset.html but I cannot find where the fields are actually transformed in html. Basically I want to change the field of the foreign key adding a link to another page. Do you hav...