django-templates

"Permission Denied" in Django template using Djapian

I've followed the Djapian tutorial and setup everything "by the book" so that the indexshell commandline supplied by Djapian shows successful queries. However, when integrating the sample search from the Djapian tutorial I get this nonsense error: TemplateSyntaxError at /search/ Caught an exception while rendering: (13, 'Permis...

Get type of Django form widget from within template

I'm iterating through the fields of a form and for certain fields I want a slightly different layout, requiring altered HTML. To do this accurately, I just need to know the widget type. It's class name or something similar. In standard python, this is easy! field.field.widget.__class__.__name__ Unfortunately, you're not allowed access ...

How to convert seconds to hh:mm:ss with the Django's date template tag ?

Hello, Edit : is there a way to easily convert {{ value|date:"Z" }} to one of the +hh:mm or -hh:mm formats (because date:"Z" returns xxxx or -xxxx seconds). Show this for more explanations about the needed format. Thank you and sorry for my ugly english. ;) ...

Django redirect not working

I can see the problem, I attached my code and error page. In my template, I have: {% if user.get_profile.is_store %} <!--DO SOME LOGIC--> {%endif%} In my view, I have: def downloads(request): """ Downloads page, a user facing page for the trade members to downloads POS etc """ if not authenticated_user(request): return H...

How to write better template tags in django...

I've seen how I can write template tags that set a context variable based on a template like this {% my_template_tag 'blah' as my_context_variable %} But I'd like to be able to do this: given that both group and user are set in the context in the view {% is_in_group group user as is_member %} {% if is_member %} #.... do stuff ....

Using breadcrumbs with django-filter, QueryDict trouble

I'm using django-filter to drill down and would like to create breadcrumbs for each item that was filtered. For example: Price ranges: 10,000+ 5,000-9,999 1,000-4,999 0-999 Bedrooms: 4 3 2 1 Each of the items under Price ranges and Bedrooms would be a link to drill down in a queryset. I'd like to create a breadcrumb such as Price ra...

Can you check the internet protocol from Django's template?

Right now, if I want to check whether the current page is accessed through http:// or https://, I will use the following Javascript in my templates and write html from document.write: <script type="text/javascript"> var protocol = document.location.protocol; if (protocol == "http:") document.write("regular"); else document.write...

Reverse for '*' with arguments '()' and keyword arguments '{}' not found.

Caught an exception while rendering: Reverse for 'products.views.'filter_by_led' with arguments '()' and keyword arguments '{}' not found. I was able to successfully import products.views.filter_by_led from the shell and it worked so the path should be correct. Here is the urls.py: (r'^led-tv/$', filter_by_led ), This is where...

Query a template for the variables it needs?

I'd like to be able to instantiate a template from a file (presumably using the django.template.loader.get_template(filename) ), and then determine the set of variables that should be defined in whatever context it is passed. I thought there would be a method on the Template object, but there doesn't seem to be. I read the docs, and t...

User authentication in Django

I learned how to authenticate users in Django months ago, but I've since upgraded and am having some problems so it occurred to me this morning that I may not have been doing it correctly from the start so I decided to ask. In my project's urls.py file I've got ^accounts/login/$ and ^accounts/logout/$ both wired up to the built-in login...

Decorators on Django Template Filters?

I have a template filter that performs a very simple task and works well, but I would like to use a decorator on it. Unfortunately the decorator causes a nasty django error that doesn't make any sense... Code that works: @register.filter(name="has_network") def has_network(profile, network): hasnetworkfunc = getattr(profile, "has_%...

Error when using Tag Cloug in Django

There are my code: {% load tag_cloud %} {% tag_cloud_for_model blog.Entry as tags with steps=6 min_count=1 distribution=log %} {% for tag in tags %} <span class="tag-{{tag.font_size|add:"1"}}"><a href="/blog/tag/{{tag.name|slugify}}/">{{tag.name}}</a></span> {% endfor %} Everything looks normal until I have 6 tag "django" in 6 di...

What is wrong with this loop in my Django view/template?

I hate to ask here but I am stumped and so were the guys in irc. The template does not display the contents of the list I am trying to display. {{ bet }} alone also displays no values. What am I missing? Template: {% for bet in bets %} <tr> <td><div>{{ bet.game_num }}</div></td> <td><div>{{ bet.home_team }}</div></td> <t...

problem with django templating system

I'm having a problem with the django templating system. I have a template with html, css, and js. When I use this template for my site, all of its margins and paddings change, and my template seems to become another template. For example margin 0 auto; seems to become margin 0 0;. Note: I have a temp.html file and, for example, in the ...

Access a model's field by another field's value in a template in Django?

Hi, I don't really know how to describe what I'm aiming at (EDIT: I want a dynamic attribute lookup), but I'm trying to do something like this <p>{{dict.{{object.field}}}}</p> in a template. I also tried: {% with object.field as field %} {{dict.field}} {% endwith %} wich didn't work either. Do you know how to tackle this properl...

Django 1.1 - comments - 'render_comment_form' returns TemplateSyntaxError

Hello, I want to simply render a built-in comment form in a template, using Django's builtin commenting module, but this returns a TemplateSyntaxError Exception. I need help debugging this error, please, because after googling and using the Django API reference, I'm still not getting any farther. Info: This is the template '_post.htm...

Django buggy template tag - 'NoneType' object has no attribute 'source'

Wondering what is causing this? Had me stumped for some time, everything checks out in console when running in pieces as a side note: the template is using the same object in other places and displaying values - the object in template is also the same one loaded in the console below error 'NoneType' object has no attribute 'source'...

Django: How to display Validation errors not specific to a field?

I have errors raised in the form's clean method (not tied to a field). How do I display them in the template? I tried {{ forms.errors }} and {{ form.non_field_errors }} but neither worked. ...

give an active to class to active link

Hello, I am writing a python website built on the back of the django framework, I am looking for a way to highlight the current link the user is on depening on what the URL, I thought doing some thing like this would work. What I have done is create a new application called nav and built some templatetags, like so, from django impor...

How to assign value in Django Templates?

I have writing a template tag and take it to the templates: {% check_somethings value1 value2 as is_checked %} {% if is_checked %} # do it {% endif %} But there are some errors. I am doing so right? check_somethings takes 2 arguments There are: @register.simple_tag def check_somethings(value1, value2): if Mymodel.objects.f...