Re: Questions about the use of for loops in django

2022-12-17 Thread jiang hao
I have solved this problem, it is my backend code's problem :( jiang hao在 2022年12月18日星期日上午7:59:15 [UTC+8]寫道: > I use a for loop in django. When I refresh the browser, the result of the > first for loop is not cleared, and the result of the second for loop is > stitched together with the first

Questions about the use of for loops in django

2022-12-17 Thread jiang hao
I use a for loop in django. When I refresh the browser, the result of the first for loop is not cleared, and the result of the second for loop is stitched together with the first one. test.html: Test full_name html_url description stargazers_count {% for item in resp_list %} {{ ite

RE: Nested for loops in templates

2018-06-15 Thread Matthew Pava
TEMPLATE_STRING_IF_INVALID) or settings.TEMPLATE_STRING_IF_INVALID From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of Mikkel Kromann Sent: Friday, June 15, 2018 6:36 AM To: Django users Subject: Re: Nested for loops in templates Thanks Matthew. The field_list is a lis

Re: Nested for loops in templates

2018-06-15 Thread Mikkel Kromann
n-a-django-template?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa > > > > > > *From:* django...@googlegroups.com [mailto: > django...@googlegroups.com ] *On Behalf Of *Mikkel Kromann > *Sent:* Wednesday, June 13, 2018 3:54 PM > *To:* Django u

Re: Nested for loops in templates

2018-06-15 Thread Mikkel Kromann
Thank you Vijay. That link seems to be a feasible path for me to take (reproduced below). Perhaps you or others can help me with an additional question (I am a bit new to both Python and Django), that I'm struggling with: Which type of data structure is Django iterating over in the templates (i

RE: Nested for loops in templates

2018-06-13 Thread Matthew Pava
?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of Mikkel Kromann Sent: Wednesday, June 13, 2018 3:54 PM To: Django users Subject: Nested for loops in templates Dear Django users. T

Re: Nested for loops in templates

2018-06-13 Thread Vijay Khemlani
As far as I know you can't do it directly in the templating system Yo could write a template tag as described here https://stackoverflow.com/questions/2894365/use-variable-as-dictionary-key-in-django-template/10700142#10700142 or use a different data structure, for example each row as a list of

Nested for loops in templates

2018-06-13 Thread Mikkel Kromann
Dear Django users. Thanks to the good advice of many people on this list, I've managed to create some nice generic class based views that work simultaneously with many models. The models may differ from each other with regards to the number of columns in their data tables as well as the naming

Re: If Statements inside For Loops

2010-01-11 Thread Karen Tracey
On Mon, Jan 11, 2010 at 1:02 PM, Dave Merwin wrote: > First of all, thanks to everyone for the help!!! > > I'm not getting any output after the else. Nothing displays in the > template. > > That is what is confusing. > > "Nothing displays in the template" sounds like either there is no user varia

Re: If Statements inside For Loops

2010-01-11 Thread Dave Merwin
First of all, thanks to everyone for the help!!! I'm not getting any output after the else. Nothing displays in the template. That is what is confusing. Dave On Jan 11, 8:58 am, Karen Tracey wrote: > On Mon, Jan 11, 2010 at 2:39 AM, Dave Merwin wrote: > > I have the following: > > > {% for gr

Re: If Statements inside For Loops

2010-01-11 Thread Karen Tracey
On Mon, Jan 11, 2010 at 2:39 AM, Dave Merwin wrote: > I have the following: > > {% for group in user.groups.all %} >{{ group.name }} >{% ifequal group.name "subscribed" %} >I'm subscribed >{% else %} >{{ group.name }} >{% endifequal %} > {% endfor %} > > The else p

Re: If Statements inside For Loops

2010-01-11 Thread G B Smith
If the docs are to be believed, {% ifequal %} does provide an option for an {% else %} clause. See http://docs.djangoproject.com/en/dev/ref/templates/builtins/#ifequal That said, I can't tell from the code above why it would not work. But if you are using Django dev version (post 1.1) then go for

Re: If Statements inside For Loops

2010-01-11 Thread andreas schmid
i think ifequal does not accept an else in the statement. Dave Merwin wrote: > I have the following: > > {% for group in user.groups.all %} > {{ group.name }} > {% ifequal group.name "subscribed" %} > I'm subscribed > {% else %} > {{ group.name }} > {% endifequal %}

If Statements inside For Loops

2010-01-10 Thread Dave Merwin
I have the following: {% for group in user.groups.all %} {{ group.name }} {% ifequal group.name "subscribed" %} I'm subscribed {% else %} {{ group.name }} {% endifequal %} {% endfor %} The else part of the statement is not rendering. What am I missing? Any help wel

IN query problem with 2 for loops on a template

2009-09-22 Thread hinnack
I have 2 querysets: events = event_dates.objects.select_related('evid', 'evid__type', 'evid__category').all() inner_qs = event_dates.objects.all().values('pk').query loc = locations.objects.filter(locid__in=inner_qs).all() render_to_response('backup.xml', {'events': events, 'locations': loc, 'con

Re: Do fields in html templates have to be displayed in {% for loops?

2009-03-12 Thread Rajesh D
On Mar 12, 12:53 pm, NoviceSortOf wrote: > In my html template i have something like > > {% for field in form %} >     {{ field.label_tag }} >     {{ field }} > {% endfor %} > > Which loops and displays the field name and field value in the form. > > On smaller forms, I would prefer to do

Do fields in html templates have to be displayed in {% for loops?

2009-03-12 Thread NoviceSortOf
In my html template i have something like {% for field in form %} {{ field.label_tag }} {{ field }} {% endfor %} Which loops and displays the field name and field value in the form. On smaller forms, I would prefer to do this manually w/o the loop by saying something like. ... {{

Do fields in html templates have to be displayed in {% for loops?

2009-03-12 Thread NoviceSortOf
In my html template i have something like {% for field in form %} {{ field.label_tag }} {{ field }} {% endfor %} Which loops and displays the field name and field value in the form. On smaller forms, I would prefer to do this manually w/o the loop by saying something like. ... {{

Do fields in html templates have to be displayed in {% for loops?

2009-03-12 Thread NoviceSortOf
In my html template i have something like {% for field in form %} {{ field.label_tag }} {{ field }} {% endfor %} Which loops and displays the field name and field value in the form. On smaller forms, I would prefer to do this manually w/o the loop by saying something like. ... {{

Do fields in html templates have to be displayed in {% for loops?

2009-03-12 Thread NoviceSortOf
In my html template i have something like {% for field in form %} {{ field.label_tag }} {{ field }} {% endfor %} Which loops and displays the field name and field value in the form. On smaller forms, I would prefer to do this manually w/o the loop by saying something like. ... {{

Re: Nested for loops in template

2008-07-18 Thread brianmac44
That worked. I just updated my entries model to include comments = generic.GenericRelation(FreeThreadedComment) Thanks. -Brian On Jul 18, 12:30 pm, "Scott Moonen" <[EMAIL PROTECTED]> wrote: > Brian, I think the solution is to add a GenericRelation to your entries > model; > seehttp://www.djang

Re: Nested for loops in template

2008-07-18 Thread Scott Moonen
Brian, without knowing exactly how your models are configured, you can do something like this: {{ p.comment_set.count }} If you use it in more than one place (e.g., as {% if p.comment_set.count %} ... {{ p.comment_set.count }} ...), you will want to optimize things so that the SQL "COUNT()" query

Re: Nested for loops in template

2008-07-18 Thread Scott Moonen
Brian, I think the solution is to add a GenericRelation to your entries model; see http://www.djangoproject.com/documentation/contenttypes/#reverse-generic-relationsfor an explanation. I think that after doing this you'll be able to access p.comments.count (assuming that the generic relation is na

Re: Nested for loops in template

2008-07-18 Thread brianmac44
Hi Scott, Thanks for your help, but I'm still having trouble. I using django-threadedcomments http://code.google.com/p/django-threadedcomments/ so its a little confusing. Here are my models http://dpaste.com/65848/ -Brian On Jul 18, 12:01 pm, "Scott Moonen" <[EMAIL PROTECTED]> wrote: > Brian,

Nested for loops in template

2008-07-18 Thread brianmac44
I have two tables, one is entries and the other is comments. In the template I would like display how many comments for each entry and some other entry data. So far I have... view: entries_list = entries.objects.filter( ...) template: {% for p in object_list %} {{ p.na

Re: Template category / subcategory with for loops?

2007-10-01 Thread [EMAIL PROTECTED]
Nono, my searching didn't pull this up in the discussion groups, so I'll take a look. Thanks much! Lance On Oct 1, 6:11 pm, "Chris Moffitt" <[EMAIL PROTECTED]> wrote: > I'm sure people are sick of me for continuing to post this, but folks keep > asking, so I'll keep posting! > > In satchmo, we

Re: Template category / subcategory with for loops?

2007-10-01 Thread Chris Moffitt
I'm sure people are sick of me for continuing to post this, but folks keep asking, so I'll keep posting! In satchmo, we used elementree to build up such a nested list. You can see the custom template tag here- http://www.satchmoproject.com/trac/browser/satchmo/trunk/satchmo/shop/templatetags/satc

Template category / subcategory with for loops?

2007-10-01 Thread [EMAIL PROTECTED]
I have been unable to wrap my brain around a simple solution for the following. I have a list of items that have a category and subcategory. I would like to print them out in a hierarchy using the template system. items = [ { 'name' : 'item1', 'category' : 'foo', 'subcategory' :

Need a little more help with for loops

2007-07-26 Thread drkfce
f="http://yui.yahooapis.com/ 2.2.2/build/treeview/assets/tree.css"> http://yui.yahooapis.com/2.2.2/build/yahoo/yahoo-</a> min.js" > http://yui.yahooapis.com/2.2.2/build/event/event-</a> min.js" > http://yui.yahooap

Re: Multiple for loops, alternating between key and value?

2007-07-25 Thread drkfce
7;VLAN': '1', 'speed': '1000', 'port': 'Gi1/6'}], 'serial': 'XXY', 'model': 'WS-X4516-10GE', 'ports': '6', 'card': 'S

Re: Multiple for loops, alternating between key and value?

2007-07-23 Thread Russell Keith-Magee
On 7/24/07, drkfce <[EMAIL PROTECTED]> wrote: > > Is there any possible way to have the first loop just display the key? Sure - you just need to walk through the data correctly. Your context contains the `switch_info`, which is a list of dictionaries. When you print {% for item in switch_info %

Multiple for loops, alternating between key and value?

2007-07-23 Thread drkfce
7;, 'duplex':'auto'}]}, {'module':'2', 'type':'RJ45', 'av_ports': [{'port':'fa2/1', 'duplex':'auto'}, {'port':'fa2/2', 'duplex':'auto'}]}]}] If you

Re: For Loops

2007-01-16 Thread Don Arbow
What you are asking is how to use a variable as a key into a dictionary, you cannot normally do this with Django template. You can get around it by using a template tag or try this: {% for date in date_list.items|dictsort:"0" %} {{ date.1 }} {% endfor %} Here's an explanation of how the a

Re: For Loops

2007-01-16 Thread Zak Johnson
Mark Jarecki wrote: Replaced the dictionary in the views.py with a list and all was fine. Whoops, sorry; I saw a variable called "Date_List" and didn't notice it wasn't a list. Glad you were able to make things work. -Zak --~--~-~--~~~---~--~~ You received th

Re: For Loops

2007-01-16 Thread Mark Jarecki
Replaced the dictionary in the views.py with a list and all was fine. Thanks Mark --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegro

Re: For Loops

2007-01-16 Thread Mark Jarecki
Thanks Zak, Problem is, when I try: {% for date in Date_List %} {{ date }} {% endfor %} I get the following rendered: 1 0 3 2 5 4 6 What I'm wanting to render is: 2007-01-17 2007-01-18 2007-01-19 2007-01-20 2007-01-21 2007-01-22 2007-01-23 Not sure where I'm going wrong. On 17/01/20

Re: For Loops

2007-01-16 Thread Zak Johnson
Mark Jarecki wrote: I imagined replacing it with something like: {% for date in Date_List %} {{ Date_List.NotSureWhatToPutHere }} {% endfor %} Much like Python loop syntax: {% for date in Date_List %} {{ date }} {% endfor %} -Zak --~--~-~--~~~---~--~~ Y

For Loops

2007-01-16 Thread Mark Jarecki
Hi there. I'm trying to create a list of days of the upcoming week in my template. I have the following, but would like to have the template instead utilise a for loop instead of hard coding the days. At present i have the following - which works: #views.py def detail(request): date_l

Re: Does the template system allow nested for loops?

2006-10-05 Thread carlwenrich
thanks much. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] F

Re: Does the template system allow nested for loops?

2006-10-05 Thread RajeshD
Yes, you can have nested loops. To access the self and parent loop counters see: http://www.djangoproject.com/documentation/templates/#for --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To po

Does the template system allow nested for loops?

2006-10-05 Thread carlwenrich
And if so, how do you refer to the loop counters? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this gro

Re: Template For Loops

2006-09-25 Thread Malcolm Tredinnick
On Mon, 2006-09-25 at 17:25 -0700, brad wrote: > Now I am getting an error of: > > Exception Type: TypeError > Exception Value: 'tuple' object is not callable > Exception Location: E:\dp1\mysite\..\mysite\urls.py in ?, line 10 > > And line ten of 'urls.py' is the following: > > (r'

Re: Template For Loops

2006-09-25 Thread brad
Now I am getting an error of: Exception Type: TypeError Exception Value:'tuple' object is not callable Exception Location: E:\dp1\mysite\..\mysite\urls.py in ?, line 10 And line ten of 'urls.py' is the following: (r'^select/$', 'mysite.polls.views.select') --~--~-~

Re: Template For Loops

2006-09-25 Thread Alan Green
On 9/26/06, brad <[EMAIL PROTECTED]> wrote: > > Hello. I am having a little trouble retreiving data from my models so > that I can use the data in my templates to create a html select. The > template creates the html select, but the select is not populated with > any options, like I want it to. Th

Re: Template For Loops

2006-09-25 Thread Rob Hudson
In your view are you passing game_name into the template context? For more info: http://www.djangoproject.com/documentation/templates_python/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To

Template For Loops

2006-09-25 Thread brad
Hello. I am having a little trouble retreiving data from my models so that I can use the data in my templates to create a html select. The template creates the html select, but the select is not populated with any options, like I want it to. Thanks in advanced for any and all ideas to get this tem