django-templates

Change Django Templates Based on User-Agent

I've made a Django site, but I've drank the Koolaid and I want to make an IPhone version. After putting much thought into I've come up with two options: Make a whole other site, like i.xxxx.com. Tie it into the same database using Django's sites framework. Find some time of middleware that reads the user-agent, and changes the templa...

Django template with jquery: Ajax update on existing page

I have a Google App Engine that has a form. When the user clicks on the submit button, AJAX operation will be called, and the server will output something to append to the end of the very page where it comes from. How, I have a Django template, and I intend to use jquery. I have the following view: <html> <head> <title></title> <script...

How do I perform query filtering in django templates

I need to perform a filtered query from within a django template, to get a set of objects equivalent to python code within a view: queryset = Modelclass.objects.filter(somekey=foo) In my template I would like to do {% for object in data.somekey_set.FILTER %} but I just can't seem to find out how to write FILTER. ...

How to disable HTML encoding when using Context in django

In my django application I am using a template to construct email body, one of the parameters is url, note there are two parametes separated by ampersand in the url. t = loader.get_template("sometemplate") c = Context({ 'foo': 'bar', 'url': 'http://127.0.0.1/test?a=1&b=2', }) print t.render(c) Af...

How does one add default (hidden) values to form templates in Django?

Given a Django.db models class: class P(models.Model): type = models.ForeignKey(Type) # Type is another models.Model class name = models.CharField() where one wishes to create a new P with a specified type, i.e. how does one make "type" to be a default, hidden field (from the user), where type is given likeso: http://x.y/P/new?...

How do I list items in my Django models?

Am working with django Publisher example, I want to list all the publishers in the db via my list_publisher.html template, my template looks like; {% extends "admin/base_site.html" %} {% block title %}List of books by publisher{% endblock %} {% block content %} <div id="content-main"> <h1>List of publisher:</h1> {%regroup publisher by...

Syntax error whenever I put Python code inside a Django template

I'm trying to do the following in my Django template: {% for embed in embeds %} {% embed2 = embed.replace("&lt;", "<") %} {{embed2}}<br /> {% endfor %} However, I always get an invalid block or some syntax error when I do anything like that (by that I mean {% %} code inside a loop). Python doesn't have {} to si...

how to combine a template from other processed templates?

Hi! I have a django project pro1 with several apps: app1, app2, app3 and so on. I want to display some top level template that contains blocks from each and every app: example_base_template.html: [header /] [left nav bar]{{ app1 rendered template }}[/left nav bar] [right nav bar]{{ app2 rendered template }}[/right nav bar] [center secti...

Django multiselect checkboxes

I have a list of objects, each with it's own checkbox, where the user can select multiple of these. The list is a result of a query. How can I mark in the view which checkboxes are already selected? There doesn't seem to be an in operator in the template language. I want something along the lines of: <input {% if id in selectedIds %}c...

Django Template System: How do I solve this looping / grouping / counting problem?

I have a list of articles, and each article belongs to a section. class Section(models.Model): name = models.CharField(max_length=200) def __unicode__(self): return self.name class Article(models.Model): section = models.ForeignKey(Section) headline = models.CharField(max_length=200) # ... I want to display the article...

DJANGO Template Variables and Javascript

Hello, When i render a page using the Django template renderer, i can pass in a dictionary variable containing various values so i can manipulate them in the page using {{ myVar }}. Is there a way to access the same variable in Javascript (perhaps using the DOM, i don't know how Django makes the variables accessible), i want to be able...

In Django, Problem with {{ block.super }}, How do I avoid duplicating a `block` in multiple template files?

For 2 child template files inheriting a block, the {{ block.super }} does not resolve Python 2.5.2, Django 1.0, Windows XP SP3 Sample skeleton code for files involved: base.html item_base.html show_info_for_all_items.html show_info_for_single_item.html FILE : base.html {% block content %} {% endblock %} FILE : item_base.html {%...

How do i use the change_form.html template in django?

I have my models and i would like to make use of the Django change_form template to edit my data, currently i have created my own template that works fine but lacks some of the basic stuff that change_form template might have, like fields validation. Please give examples showing how i should call the template from my view, and what obje...

Firefox handles xxx.submit(), Safari doesn't ... what can be done?

I'm trying to make a pull down menu post a form when the user selects (releases the mouse) on one of the options from the menu. This code works fine in FF but Safari, for some reason, doesn't submit the form. I re-wrote the code using jquery to see if jquery's .submit() implementation handled the browser quirks better. Same result, wo...

In Django, is it possible to access the current user session from within a custom tag?

I am writing a custom tag in Django that should output a value stored in a user session, but I cannot find a way to access the session object from within a custom tag function. Is there any way to do this, without manually assigning the session object to a context variable? ...

MVC and django fundamentals

Pretty new to this scene and trying to find some documentation to adopt best practices. We're building a fairly large content site which will consist of various media catalogs and I'm trying to find some comparable data / architectural models so that we can get a better idea of the approach we should use using a framework we've never ma...

What are the steps to make a ModelForm work with a ManyToMany relationship with an intermediary model in Django?

I have a Client and Groupe Model. A Client can be part of multiple groups. Clients that are part of a group can use its group's free rental rate at anytime but only once. That is where the intermediary model (ClientGroupe) comes in with that extra data. For now, when I try to save the m2m data, it just dies and says I should use the C...

printing a list of persons with more than one home, each home with more than one phone number...

I have a class Person which can have several Homes, each one with one or many Phone numbers. I have defined the classes, but now i am trying to create a view wich list every person, with all its homes and all the phone numbers for each home address... something like: john smith 123 fake str 305-99-8877 305-99-8876 321 oak road 44...

How to process two forms in one view?

I have two completely different forms in one template. How to process them in one view? How can I distinguish which of the forms was submitted? How can I use prefix to acomplish that? Or maybe it's better to write separate views? regards chriss ...

templatetags don't refresh

I have two templatetags in my app which contain forms which show entries in db. When I alter data or add new entry to db, the forms show the old data. While in admin panel everything is correct (updated). When I restart the server (I mean manage.py runserver) forms show updated db entries. How to make the forms show updated data? regard...