django-templates

Using safe filter in Django for rich text fields

I am using TinyMCE editor for textarea fileds in Django forms. Now, in order to display the rich text back to the user, I am forced to use the "safe" filter in Django templates so that HTML rich text can be displayed on the browser. Suppose JavaScript is disabled on the user's browser, TinyMCE won't load and the user could pass <script...

Debugging Django Admin Template Resolution

Hi, Can someone point me to the code or a way that I can say print to screen which admin template is being used? It happens many a time when I am replacing a admin template for an model that I add the template and hit the page and bham... still the same template. Usually its a case issue or something like that... but it takes me a whi...

Django xml for flash?

Hi guy, how ill write a xml file for use with flash?, Django Doc dont have nothing about XML (just for Feeds).... Tutorial? Thansk ...

Django: Problem with {% cycle %}

Hi This is taken directly from my Django template: {% for day in days %} <!-- {% cycle 'day' 'day' 'day last' as cls %} --> {% rounded "black" cls %} {# Custom tag giving me rounded borders. #} ... {% endrounded %} {% endfor %} I have commented out the {% cycle %} because I only use it to set "cls" to "day last" every third i...

Django, category and subcategories

Hi guys, im working category and subcategories with the DataModel, all is fine in this part, but i need to use my category and subcategories in my Menu Nav, im try to use this Jquery menu , and im rendering my menu with subcategories, but im lost with rendering the subcategories in the way: <ul> <li> <a href="#">Category</a> ...

Display Django Code from a Django template

Hi, I am trying to display Django source code from a Django template.. However, I cannot find a tag similar to HTML's pre or xmp. Can someone point me to the right direction. Thanks EDIT Heres the code Also, I have a block with the same name.. which springs the error ...

how to overwrite django template render method handling

In my application, I am sending periodic cron and background task requests to refresh the cache of pages. While sending a force_refresh kwarg from the view is easy, there's no apparent way to send the force_refresh kwarg to methods being accessed from the template. There are plenty of these I'm using, and it would just make things more c...

how to use math remainder in django template?

Hi; I would like to change the class attribute of an li after each 4 elements (that means 5th, 9th, 13th li element classes should be changed). I have tried something like below but it gave me an syntax error: Could not parse the remainder: '%4' from 'forloop.counter%4' {% for p in plist %} {% ifequal forloop.counter%4 1 %} <li class...

DJANGO - How to use "Custom Attributes" in an external app form without permanent change

I would like to change an external apps form fields to use in a particular template of my application. I would like to give attribute values for the fields as shown below. body = forms.CharField(widget=forms.Textarea(attrs={'class':'textarea', 'rows':'', 'cols':"", 'onclick':"this.style.height='250px';"})) title = forms.CharField(widg...

Django, custom tag... how?

Hi guys, i would like to make a django custom tag for display 10 entry title from the category where the user is reading a article... but how ill do?, i need to send the category from the actual entry... Any idea? Thanks ...

Django : debugging templatetags

How on earth do people debug Django templatetags? I created one, based on a working example, my new tag looks the same to me as the existing one. But I just get a 'my_lib' is not a valid tag library: Could not load template library from django.templatetags.my_lib, No module named my_lib I know that this is probably because of someth...

How can I get the domain name of my site within a Django template?

How do I get the domain name of my current site from within a Django template? I've tried looking in the tag and filters but nothing there. ...

How to markup form fields with <div class='field_type'> in Django

I wasn't able to find a way to identify the type of a field in a django template. My solution was to create a simple filter to access the field and widget class names. I've included the code below in case it's helpful for someone else. Is there a better approach? ## agency/tagutils/templatetags/fieldtags.py ##########################...

Use middleware or a custom template tag for infrequently changing snippet

I've got a small snippet that I want in my sidebar. The snippet will be visible on each page, and while cheap to fetch (about 50ms on my super-slow netbook!), will change so infrequently that I'd quite like to cache it (partly because I've yet to use Django's cache framework, and I'd like to learn). I'm not sure what the best way to go ...

django-multilingual and switching between languages on template side

I am trying to use django-multilingual and setup it properly. But what I found is that everything is clear for django-multilingual except a template usage example. I just started to use django and I don't know, maybe because of this reason, I cannot figure out how to switch between languages on template side. Is there any example that ...

Haystack search results: how to use different templates for different models in page.object_list?

I'm adding search to an existing Django site, using Haystack with a Solr backend. I want my search to work across several different models, and return a single set of of results. When iterating through the results, I would like to format each result based on what model type it is -- e.g. if the result is an Apple, use one result templa...

Is there a template language for PHP that's almost similar to the Django template language?

Is there a template language for PHP that's almost similar to the Django template language? ...

Aggregates in Django templates

In a Django application, I want to display a multi-level (but fixed-depth) tree of model objects in table form. The HTML would look something like this: <tr><td rowspan="2">group 1</td><td>item 1.1</td></tr> <tr><td>item 1.2</td></tr> <tr><td rowspan="3">group 2</td><td>item 2.1</td></tr> <tr><td>item 2.2</td></tr> <tr><td>item 2.3</td>...

Django Templating: how to access properties of the first item in a list

Pretty simple. I have a Python list that I am passing to a Django template. I can specifically access the first item in this list using {{ thelist|first }} However, I also want to access a property of that item... ideally you'd think it would look like this: {{ thelist|first.propertyName }} But alas, it does not. Is there any temp...

Template-level model methods in Django to respect both DRY and MTV (MVC)?

As an example, let's say there's a Tshirt model on a shopping site, and it will have "summary" markup with a thumbnail, name and price: <div> <a href="detailspage">Awesome TShirt!</a> <img src="thumbnail.jpg" /> <span class="price">$55.99</span> </div> Since this will be on many different pages, I don't want to have to typ...