django-templates

Django MPTT - tree filtering

I am using MPTT's templatetag to render my genre tree. {% for genre, structure in genres|tree_info %} {% if tree.new_level %}<ul><li>{% else %}</li><li>{% endif %} {{ genre.name }} {% for level in tree.closed_levels %}</li></ul>{% endfor %} {% endfor %} The thing is, my genre object has is_visible property w...

Django Newbie : "Reverse not found"

I have a line in a Django form : {% for aa in my_array %} which seems to be triggering this error : Template error Caught an exception while rendering: Reverse for 'dev_env.profiles.views.viewPlan' with arguments '('',)' and keyword arguments '{}' not found. What does this error message really mean? I suspect that...

How to make project templates and Satchmo templates co-exist?

I'm working with a Satchmo installation that resides within an existing project. This project has its own templates as well as templates for some of the various apps that are installed. Some of these app-specific templates have their own app_base.html variations that expect to derive form base.html. I'd like to be able to do the same ...

Is it okay to extend a base view in Django's error pages (HTTP 404 and 500)?

Django's views documentation states that "the default 500 view passes no variables to this template and is rendered with an empty Context to lessen the chance of additional errors," but is it okay to use the {% extends %} tag to re-use a base view in the 500 Server Error page (500.html)? ...

Django named urls, generic views?

So, here is one of my urls.py urlpatterns = patterns('items.views', url(r'^(?P<item_id>[\d+])/$', 'view_listing', name="item_view"), ) And in my template, I can do this: <a href="{% url item_view 1 %}">here</a> and I'll get a link to the right page. Everything works great! But, here is another one urlpatterns = patterns('django....

Controller logic and template logic, where do you draw the line with pagination?

The whole point of an MVC framework is to separate design (templates) from logic (controllers). However, template languages often afford a limited degree of "design logic" to occur. This includes basic if statements, loops, filtering, etc. I've created a Django template tag that can take any list or QuerySet and "pagify" it. It split...

write a table with empty cells based on dictionary of values

I have this view in my app: def context_detail(request, context_id): c = get_object_or_404(Context, pk=context_id) scs = SherdCount.objects.filter(assemblage__context=c).exclude(count__isnull=True) total = sum(sc.count for sc in scs) table = [] forms = [] for a in c.assemblage_set.all(): for sc in a.sherdcount_set.all(): for...

How can I lookup a UserProfile value in all of my templates?

I have a flag attached to my "UserProfile" record for logged in users that lets me know whether the user is enabled for "new features" on my site. I want to be able to check this django template variable in all of my templates to hide/show new features I already used: {% if user.is_authenticated %} To check for logged in users, I ...

Django Admin Template Overriding: Displaying checkboxselectmultiple widget

Have 2 tables Domain and Group having one to many relationship. These tables have many to many relationship with User table On the User admin interface I am rendering the Group and Domain as CheckboxSelectMultiple widgets. Is it possible to present this in a table form with 2 columns: Domain in one column and the list of groups belong...

django: form.fields not iterating through instance fields

I am trying to iterate through form.fields in a template and for: {% for field in form.fields %} {{ field }}, {% endfor %} I am getting a list of the field names ("name, description...") instead of the html code that is rendered when using the following: {{ form.name }}, {{ form.description }} (the output in this case is: <in...

Django: specifying a base template by directory

I'm working on a Django site that has multiple sections and subsections. I'd like to have several depths of template inheritance: a base template for the whole site, one base template for each section that inherits from the root base template, and so on. Here's a simplified version of my desired directory structure: base.html section1/ ...

How can I make the Django contrib Admin change list for a particular model class editable with drop downs for related items displayed in the listing?

Basically I want to have an editable form for related entries instead of a static listing. ...

How to make Django slugify work properly with Unicode strings?

What can I do to prevent slugify filter from stripping out non-ASCII alphanumeric characters? (I'm using Django 1.0.2) cnprog.com has Chinese characters in question URLs, so I looked in their code. They are not using slugify in templates, instead they're calling this method in Question model to get permalinks def get_absolute_url(self)...

[Django Templates] 'for' loop through form fields and excluding one of the fields with 'if'.

Hi, The problem I'm struggling with is as follows: I have: {% for field in form %} {{ field }} {% end for %} What I want is to put an 'if' statement to exclude a field which .label or whatever is provided. Like: {% for field in form%} {% if field == title %} {% else %} {{ field }} {% endif %} {% endfor %} I...

Django Template - New Variable Declaration

Let me preface by I am just starting Python so if this is really a simple question ^_^ I have a html file with the following content: {%for d in results%} <div class="twt"> <img src="{{ d.profile_image_url }}" width="48px" height="48px" /> <span> {{ d.text }} </span> <span class="date">{{ d.created_at }}</span> </div> {...

django templates stripping spaces?

Hi stack overflow, I guess this is a really novice question, still I'm having trouble with django templates and CharField models. So I have a model with a CharField that creates a slug that replaces spaces with underscores. If I create an object Somename Somesurname this creates slug Somename_Somesurname and gets displayed as expected ...

[Django Templates] How to get 'switch-case' statement functionality in Django templates?

Hi, I found a link to have a 'switch' tag in Django templates, but I was wondering if this can be somehow achieved without it. Using only the stuff which comes with Django? Basically is there other way then using multiple 'if' or 'ifequal' statements? Thanks in advance for any tips/suggestions. ...

Should I use a fieldset for this?

I have a queryset. I'm trying to display a feedback form for each of items in the queryset. What's a good way to approach this? Attach the model to a fieldset and then iterate through the forms in a fieldset, displaying the model information? Or loop through both the queryset and fieldsets separately in the template? ...

Fetching ManyToMany objects from multiple objects through intermediate tables

Is there an easy way to fetch the ManyToMany objects from a query that returns more than one object? The way I am doing it now doesn't feel as sexy as I would like it to. Here is how I am doing it now in my view: contacts = Contact.objects.all() # Use Custom Manager Method to Fetch Each Contacts Phone Numbers contacts = PhoneNumber.obje...

How to pass an array in Django to a template and use it with JavaScript

I want to pass an Array to a template and afterwards use it via JavaScript. In my views.py I have: arry1= ['Str',500,20] return render_to_response('test.html', {'array1': arry1}) var array1 = {{ array1 }}; but when I visit the website it puts out: var array1 = [_39;Str_39;,500,20]; (without the _ sign (otherwise stackoverflow change...