473,394 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Django forloop template variables

i am trying to learn django, after starting off with python for sometime as a beginner.
after comfortably going through django book for the initial
few topics iam stuck at trying to understand template variables-like (forloop.counter,forloop.revcounter, etc)
kindly help.
note that iam a beginner.
thank you
Jan 15 '12 #1
1 5688
Varsha1285
16 16bit
Ok so as you are aware of python then For loop functionality i.e., iterating over sequences like of array ,dictionary and list etc. same for Django.
What differs is Syntax-
List->
suppose you have list named cars and elements are present in it like Suzuki,Tesla,Mahindra.
{% for x in cars %}
<h1>{{ x }}</h1>
{% endfor %}

this for loop will iterate through the elements of list cars and will return the elements .
Dictionary->
{% for x in cars %}
<h1>{{ x.brand }}</h1>
<p>{{ x.model }}</p>
<p>{{ x.year }}</p>
{% endfor %}

here Output will be-
Suzuki
Sedans
2003
Tesla
Model x
2010,
Mahindra
Thar
2006
Feb 9 '23 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Me | last post by:
I am not understanding an aspect of how to implement a class template in a ..cpp file. What I do know is that there are at least two problems with my understanding of how to accomplish the...
1
by: Alexander Stippler | last post by:
Hello, I have some template class, where I want to initialize an array with some default value depending on a template parameter. Therefore I have some traits class. Just like this: template...
0
by: Adriano Coser | last post by:
Hello. I'm trying to compile a DLL with Visual C++ .NET 2003 and I'm facing an error declaring template variables with prototypes. I donīt know if I'll be able to explain my scenario, but...
9
by: vivekian | last post by:
Have a couple of global variables of a class type which i have declared and defined in the application. 1. Not sure where should the global variables be placed ? 2. Would i need to forward...
1
by: johnsi | last post by:
I have downloaded some asp .net source code and I see some global template variables in the html code in the aspx files. These variables show up as . The app assigns these from data in an XML...
3
by: Yohan | last post by:
Hello, I have a question concerning the template classes and their parameters. Is it possible to set a condition on the template parameters in a way that could block the compilation if the...
6
by: jiake2007 | last post by:
Hi all, I'm trying to write a template class that calls a function from one of its template parameters: template <class T> class Foo { public: Foo(T t): t(t) {}
0
by: =?Utf-8?B?U2l2YXByYWthc2hTaGFubXVnYW0=?= | last post by:
Hi I want to have a MS-WORD template and which should be taken as a input to the C# application. I will have some template variables in that template (.dot ) file those should be replaced during...
1
by: kernel1983 | last post by:
I look it up in PyPI There are info about Django: Package Score Description Django096 0.96 6 Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic...
8
by: Lawrence | last post by:
Hi Is there any way of using variables in XSLT? I have been using <xsl:param name="showDetails"/and want to be able to set it to say 1 or 0 dependent on certain XSL:if statements throughout...is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.