django-templates

Is there a way to specify a value from a list of one-to-many models at Django's Template?

Is there a way to specify a value from a list of one-to-many models at Django's Template? For example I can do this in the shell: author.book_set.get(publisher=my_publisher). However I want something like that in my template. I'm only passing Authors, a list of Author and publisher to the template. Models: class Publisher(models.M...

Show page items count in django pagination.

Hi, everyone! I'm trying to figure out how to show something like "Showing 1-10 of 52" using django pagination in my templates. I accomplished the pagination itself but nothing comes to my mind about this requirement. Any ideas? ...

How do I do a if a in list_b test in Django 0.96 Templates?

How do I do a if a in list_b test in Django 0.96 Templates? I'm having a list of checkboxes and a variable containing a list of corresponding values from a previous submit of the checkboxes. Now I want to set all checkboxes in the list to checked="checked" and I usually use a "if a in listb" test for this. But this doesn't seem to be p...

YSlow Best Practices with Django apps, How to implement them?

Hi, I have an django 1.1.1 app, actually in developement, thinking in best practices I ran the YSlow test (Grade E Ruleset applied: YSlow V2 ) it recomends: Grade F on Add Expires headers -There are 37 static components without a far-future expiration date. Grade F on Use a Content Delivery Network (CDN) ...

Why is my Django app not displaying dynamic images when the path is correct?

My Django 1.1 app uses dynamic images. I'm confused about why the path generated from my template tag: {{image_product.photo.path}} looks correct, but does not display the requested image. This generates a path that works: src='/media/{{image_product.photo}}' => <img src='/media/lcdtvs/product1.jpg'> This DOES NOT work: src='{{...

Django - Dynamic include

Hi everybody, I'm new to Django development and I'm a little bit confused with the templates and the newforms functionalities. I need to perform a dynamic include or extends on Django, and I'm not sure if it's possible. I have my index.html template page, and one of the available funcionalities on it (among others) is the login form. Th...

Django templatetag for rendering a subset of html

I have some html (in this case created via TinyMCE) that I would like to add to a page. However, for security reason, I don't want to just print everything the user has entered. Does anyone know of a templatetag (a filter, preferably) that will allow only a safe subset of html to be rendered? I realize that markdown and others do this....

Optional ImageField (Django)

Hi all, I'm having a problem with an ImageField in one of my models. It is set to blank=True, null=True (it is optional.) When I loop through a list of objects and use object.thumbnail.url, I get "Caught an exception while rendering: The 'thumbnail' attribute has no file associated with it." This only happens if no thumbnail has bee...

Customize HTML Output of Django ModelForm

I am trying to add multiple inline form items to a page using Djangos ModelForms. I need Select boxes bound to database models. The forms are formatted and placed in a tabular format so I need to display only the ModelForm without ANY surrounding HTML. class LeagueForm(ModelForm): league = forms.ModelChoiceField(queryset=League.objects....

Can we append to a {% block %} rather than overwrite?

In my core.html I have a block labeled javascript. It would be great if I can append more lines to this block without overwriting everything in it. ...

Dynamically Display field values in Django template (object.x)

Hi Guys, I am currently working on an app that uses custom annotate querysets. Currently i have 2 urls setup, but i would need one for each field that the users would like to summarize data for. This could be configured manually, but it would violate DRY! I would basically have +-8 urls that basically do the same thing. So here is wha...

Using keys with spaces

Is there a way to do something like the following in Django templates? {% for hop in hops%} <tr> <td>{{ hop.name }}</td> <td>{{ hop.mass }}</td> <td>{{ hop."boil time" }}</td> </tr> {% endfor %} The hop."boil time" doesn't work. The simple solution is rename the key boil_time, but I'm interested in alt...

Does Django cache templates automatically?

I'm new to Django and trying to implement a voting system between two images. However, it looks like the page is being cached or something because when I refresh it, some values are wrong. I have no cache setup in my Settings. Here is the View: def rate(request, type): photos = Photo.objects.order_by('?')[:2] c = Context({"ph...

How can I get a variable passed into an included template in django

Hi, I am a Django newbie and am unable to achieve something trivial. Please help me with this. I am setting a variable pgurl in my views.py Am able to access the variable {{pgurl}} in my with_tag.html template. This template includes a pagination.html template into itself In pagination.html I am unable to use the variable {{pgurl}} an...

How to produce a list ordered by a manyToMany field and display it using {% ifchanged %} in a template?

I have two models, EqTD (EquivalentTextDescription) and location. EqTD has a manytomany relation to location. I need to produce a list of all EqTDs ordered by location name ('name' is a field in the location model). I'm getting the queryset of EqTDs thus: tEqTDs = EqTD.objects.order_by('location__name') which I'm hoping will produce d...

Calling small app in template : Django

Lets say I have a website with a small application that lists the 10 newest members, or something dynamic like that. I want this to view on every page, perhaps in a sidebar. How would i go about doing this. My thoughts on the mather... I might not get the whole django thing just yet, but when I have a url like /foo/ calling a view bar -...

Django MultiWidget Phone Number Field

I want to create a field for phone number input that has 2 text fields (size 3, 3, and 4 respectively) with the common "(" ")" "-" delimiters. Below is my code for the field and the widget, I'm getting the following error when trying to iterate the fields in my form during initial rendering (it happens when the for loop gets to my phone...

url template tag in django template

guys: I was trying to use the url template tag in django, but no lucky, I defined my urls.py like this urlpatterns = patterns('', url(r'^analyse/$', views.home, name="home"), url(r'^analyse/index.html', views.index, name="index"), url(r'...

Problem with logic in Django template

Supose this portion of a Django template. regs is a list of Reg objects. Reg.editable is a BooleanField. I want to render a radio button per element in the list. If r.editable is False, the radio button must be disabled: {% for r in regs %} <input type="radio" value="{{ forloop.counter }}" {% if forloop.first %}checked="checked"{% endif...

Check if a session variable is set

I'd like to check if a certain variable is set inside my template...if it is set, an image will be displayed...I have written this as below in my template, but apparently it's not working. {% if request.session.chosen_year %} <a href="/undo_year/"> <img src="{{ MEDIA_URL }}img/undo.gif" border="0" alt="Reset" /> </a> {% e...