django template script variable usage and declaration

24 views
Skip to first unread message

Haroon idrees

unread,
Dec 12, 2008, 2:04:19 AM12/12/08
to django...@googlegroups.com
Hello
I am new to python world . any one can help to guide how we
declare variables in python template script and use in if else block
and vary it

for example
//need to declare variable here
//for example x=0
{% for message in message %}
//need to put if condition here
//ifequal x 0
<tr bgcolor="#DDDDDD">
//x=1
//need to put else condition here
<tr bgcolor="#FFFFFF">
x=0
<td width='20%'> <a
href="/restmessage/mzubair.ahmed?format=xml">mzubair.ahmed </a></td>

<td width='60%'>
test
</td>
<td width='20%'> 2008-12-12 05:13:45.788901</td>
</tr>

{%endfor%}

--
Regards
Haroon Idrees
Sr.Software Engineer
cell:92321-2066747
msn:haroon...@hotmail.com
http://www.linkedin.com/in/haroonob

Daniel Roseman

unread,
Dec 12, 2008, 5:57:32 AM12/12/08
to Django users
On Dec 12, 7:04 am, "Haroon idrees" <haroo...@gmail.com> wrote:
> Hello
>      I am new to python world . any one can help to guide how we
> declare variables in python template script and use in if else block
> and vary it
>
> for example
> //need to declare variable here
> //for example x=0
> {% for message in message %}
> //need to put if condition here
> //ifequal x 0
> <tr bgcolor="#DDDDDD">
> //x=1
> //need to put else condition here
> <tr bgcolor="#FFFFFF">
> x=0
>         <td width='20%'> <a
> href="/restmessage/mzubair.ahmed?format=xml">mzubair.ahmed </a></td>
>
>                         <td width='60%'>
>                                 test
>                         </td>
>                         <td width='20%'> 2008-12-12 05:13:45.788901</td>
>                 </tr>
>
>  {%endfor%}
>

No, you can't do that, by design.

But a quick reading of the documentation for the for tag would show
you how it should be done: use forloop.counter0.
See http://groups.google.com/group/django-users/browse_thread/thread/3edfafff2f28506
--
DR.

bruno desthuilliers

unread,
Dec 12, 2008, 7:36:46 AM12/12/08
to Django users
On 12 déc, 11:57, Daniel Roseman <roseman.dan...@googlemail.com>
wrote:
> Seehttp://groups.google.com/group/django-users/browse_thread/thread/3edf...


Or if it's just to alternate between odd and even rows, use the
builtin {% cycle %} tag:
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#cycle


Haroon idrees

unread,
Dec 14, 2008, 4:53:38 AM12/14/08
to django...@googlegroups.com
I try cycle tage but it also give some error can please tell me what
is write Syntax of cycle tag
--
Regards
Haroon Idrees
Sr.Software Engineer
Etilize Pakistan
cell:0321-2066747
msn:haroon...@hotmail.com
http://www.linkedin.com/in/haroonob

bruno desthuilliers

unread,
Dec 14, 2008, 11:59:22 AM12/14/08
to Django users
On 14 déc, 10:53, "Haroon idrees" <haroo...@gmail.com> wrote:
> I try cycle tage but it also give some error can please tell me what
> is write Syntax of cycle tag


It's in the documentation. Just follow the link I gave in my previous
post.

Haroon idrees

unread,
Dec 14, 2008, 12:06:21 PM12/14/08
to django...@googlegroups.com
after follow the documentation i face the following error
File "C:\Program
Files\Google\google_appengine\lib\django\django\template\__init__.py",
line 273, in parse
compiled_result = compile_func(self, token)
File "C:\Program
Files\Google\google_appengine\lib\django\django\template\defaulttags.py",
line 434, in cycle
raise TemplateSyntaxError("Invalid arguments to 'cycle': %s" % args)
TemplateSyntaxError: Invalid arguments to 'cycle': ['cycle', "'row1'", "'row2'"]

bruno desthuilliers

unread,
Dec 14, 2008, 4:16:34 PM12/14/08
to Django users
On 14 déc, 18:06, "Haroon idrees" <haroo...@gmail.com> wrote:
> after follow the documentation i face the following error
> File "C:\Program
> Files\Google\google_appengine\lib\django\django\template\__init__.py",
> line 273, in parse
> compiled_result = compile_func(self, token)
> File "C:\Program
> Files\Google\google_appengine\lib\django\django\template\defaulttags.py",
> line 434, in cycle
> raise TemplateSyntaxError("Invalid arguments to 'cycle': %s" % args)
> TemplateSyntaxError: Invalid arguments to 'cycle': ['cycle', "'row1'", "'row2'"]

And where's your code ? Are we supposed to use crystal ball ?-)

Reply all
Reply to author
Forward
0 new messages