In Django's template system, how do I make it to do different things sometimes?

{% for p in posts %}
    <div style="width:50px;">
    blah
    </div>
{% endfor %}

However, what if I want the div to be 100px 75% of the time? 25% of the time? Randomized.

Answers


Logic does not go into templates.

Solution: write a new template tag that returns a random number, and use that for the width.

http://docs.djangoproject.com/en/1.2/howto/custom-template-tags/

Your template would then look like:

{% for p in posts %}
    <div style="width:{% myrandomtag 0 100 %}px;">
    blah
    </div>
{% endfor %}

Or whatever. Put your required logic in the python code for the tag.


random filter should do the thing


Need Your Help

Date & Time using android spinners

android xml user-interface

I'm looking to replicate the functionality shown on the android developer app tutorial.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.