473,606 Members | 3,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Django forloop template variables

13 New Member
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.counte r,forloop.revco unter, etc)
kindly help.
note that iam a beginner.
thank you
Jan 15 '12 #1
1 5704
Varsha1285
16 New Member
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,Ma hindra.
{% 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
4250
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 definition of a template outside the class. One problem is how to refer to a typedef that is a member of the classe's public interface in the .cpp file. The second problem is that if I modify my code to use the template variables and not my typedefs,...
1
1640
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 <typename T> DenseVector<T>::DenseVector(long size) { _allocate(); // allocate memory;
0
1098
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 let's try. The class TSample has a pointer (my smart pointer implementation) to a IList (an indirect list based on the same smart pointers) to the type TFontCache.
9
2904
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 declare the class before the global variable is declared ? Thanks, vivekian
1
1137
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 file. Where can I find information on how these assignments are made. It's not readily apparent in the source code and I have not been able to find any help on the subject. I'm using Visual Studio .NET 2003 and I have done a fair amount of
3
3489
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 condition isn't true? (e.g. by throwing an error message to the compiler). And is it possible to use this type of condition to make the compiler choose the best method (between some others). Here is an example to illustrate my question:
6
351
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
1120
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 run time by the C# object. Please give some sample to work around this. Thanks.
1
2323
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 design. DjangoPaste 0.0 6 Integration of Python Paste and Django TurboDjango 0.95w2 6 Django template for TurboGears, need Django to work
8
3447
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 this possible? Kind Regards Lawrence
0
7978
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8461
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8448
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8317
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5987
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5470
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4010
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2454
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1313
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.