django-templates

Django: check for generic type in template?

I'm using generic types in my Profile model: user_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() details = generic.GenericForeignKey('user_type', 'object_id') But now I want to check if a user is a certain type from within my template. I can get the user type with {{ user.get_profile.user_type }} but t...

django error:Invalid block tag: 'endblock'

why?? thanks ...

Django template context function without running automatically

Sorry or the confusing title! It's actually a lot simpler than it sounds. I've got a function: def get_messages(request): # do something expensive with the request return 'string' I want to be able to call that function from the template, so I've strapped in with a context processor: def context_processor(request): retur...

Django Template For Loop Removing <img> Self-Closing

Django's for loop seems to be removing all of my <img> tag's self-closing...ness (/>). In the Template, I have this code: {% for item in item_list %} <li> <a class="left" href="{{ item.url }}">{{ item.name }}</a> <a class="right" href="{{ item.url }}"> <img src="{{ item.icon.url }}" alt="{{ item.name }} Logo." /> </a...

Is it safe to render user-created Django templates?

Is it safe to let users make their own Django templates with a set of pre-defined variables, and then render this template on the server? I would only pass a very limited set of parameters to render, all of which are strings. Templates would be something like: hey, my name is {{name}}. So, the question is, are there any django templat...

Python template help

I'm using App Engine's web-app templating system (similar if not identical to django) Normally I render templates from my static directory /templates/ as follows in my main handler: dirname = os.path.dirname(__file__) template_file = os.path.join(dirname, os.path.join('templates', template_name)) output = template.render(template_f...

Django - Two templates inheriting same parent, but nesting one another too?

I'm having some trouble with template inheritance. What I'm trying to achieve is a threaded comment system (using Django's comment framework). This requires comments who's DOM structure virtually identical to be nested. Here's the general layout of the issue: B and C inherit A C is nested inside of B (with include) Template D includes ...

Easy way to submit POST data from a hyperlink in Django? Equivalent of Rails' `button_to`?

Is there a quick way to submit (pre-defined) POST data from a hyperlink in a Django template? I've got an 'add this to my favourites' link on page. I'm currently doing this with a GET request, which obviously breaks all kinds of rules. I could manually build a form and have the link submit it with Javascript. I'm looking for an automat...

Unable to get custom context processor to be invoked

I am trying to create a custom context processor which will render a list of menu items for a logged in user. I have done the following:- Within my settings.py I have TEMPLATE_CONTEXT_PROCESSOR = ( 'django.contrib.auth.context_processors.auth', 'mysite.accounts.context_processors.user_menu', ) Under the accounts submodule ...

Django problem with extends template tag

Hi, I'm trying to put variable from context processor into tag template 'extends': {% extends {{ base_template|default:"mainpage.html" }} %} but I got an exception: Exception Value: 'extends' takes one argument my context_processors.py: from django.conf import settings def search(request): """Adds settings for test""" return { ...

View referenced by two urls and url tag

I am using url tag in my template for a view, that is used by two different urls. I am getting the wrong url in one place. Is there any way to force django to retrieve different url? Why it doesn't notify my, that such conflict occured and it doesn't know what to do (since python zen says, that is should refuse temptation to guess). Cod...

Why were the original authors of Django against include tags?

In this excellent Google Tech Talk by Jacob Kaplan-Moss, Jacob says that they added support for the include template tag despite previous dogmatic objections, and says that people shouldn't use it. Does anyone know why? A quick search didn't show anything that would explain why. There's nothing relevant in the now-fixed ticket where sup...

Storing Content with Complex Structure using Django

Is there a recommended best-practice for storing content that has a complex structure. For example, suppose a typical "article" I am trying to serve may have the following hierarchy: Header #1 Subheader #1.a) Text content Image content Text Content Subheader #1.b) Text Content Other complex content ty...

problem with select and related model

I have models like this: class IdfPracownicy(models.Model): nazwa = models.CharField(max_length=100) class IdfPracaOpinie(models.Model): nazwa = models.CharField(max_length=30) class IdfPraca(models.Model): numer_idf = models.ForeignKey(IdfPracownicy) [...] opinia = models.ForeignKey(IdfPracaOpinie) uwagi = model...

Django URL Parameter Key Used Twice

I have a simple Django view that just returns URL parameters, but if I use the same parameter key multiple times, I cannot seem to access it. Consider the following set-up: urls.py: (r'^header/$',header) View function: def header(request) return render_to_response('header.html',locals(),mimetype='text/plain') Template: {{ req...

Django: Sort order the list in objects

I have list1 in order by id. Like this: ['4','2','1','17'] #edited How to get list2 from object Entry in order of list1. In the case Query ValueList, as well as on the question. [u'4', u'2', u'1', u'17'] Because some properties are not in QuerySet Thanks for your answers ! ...

How to get a list of queryset and make custom filter in Django

I have some codes like this: cats = Category.objects.filter(is_featured=True) for cat in cats: entries = Entry.objects.filter(score>=10, category=cat).order_by("-pub_date")[:10] But, the results just show the last item of cats and also have problems with where ">=" in filter. Help me solve these problems. Thanks so much! ...

Django Custom Template Tages: Inclusion Tags

Hello world! Im trieng to build my own template tags Im have no idea why I get the errors I get, im following the django doc's. this is my file structure of my app: pollquiz/ __init__.py show_pollquiz.html showpollquiz.py This is showpollquiz.py: from django import template from pollquiz.models import PollQuiz, Choice r...

Django: Template should render 'description' not actual value

Hi, in a Model I have a CharField with choices: class MyModel(models.Model): THE_CHOICES=( ('val',_(u'Value Description')), ) ... myfield=models.CharField(max_length=3,choices=THE_CHOICES Now in the template I access an instance of MyModel: {{ my_instance.myfield }} Of course the gives me val instead of Value ...

How to access outermost forloop.counter with nested for loops in Django templates?

Is it possible to access the forloop.counter for the outermost for loop in the following template in Django: {% for outerItem in outerItems %} {% for item in items%} <div>{{ forloop.counter }}.&nbsp;{{ item }}</div> {% endfor %} {% endfor %} forloop.counter returns the innermost for loop's counter in the above example ...