Django developer server auto quit when iterate QuerySet in template

4 views
Skip to first unread message

Huy Bùi

unread,
Sep 24, 2019, 10:54:04 AM9/24/19
to Django users
    Hello,

 Everytime i try to access a url, the Django developer server auto quit without any log about what happens.
 After debugging a little bit, i find out if i remove this block of code in the template file, i can access the web page normally:

 
<select name="department1" class="department">
 
<option value=""></option>
 {% for d in departments %}
 
<option value="{{ d.id }}"> {{ d.name }} - {{ d.department_code }} </option>
 {% endfor %}
 
</select>

 But i can iterate the QuerySet in the view normally, it seems like there aren't any problem iterating the QuerySet:

def edit(request):
    departments
= Department.objects.filter()
   
for d in departments:
       
print(d.id, d.name, d.department_code)

   
return render(request, 'edit/edit.html', {'departments': departments})

 I have no idea what is happening and it's driving me crazy. Any help would be appreciated. Thank you.

Deep Sukhwani

unread,
Sep 24, 2019, 12:01:17 PM9/24/19
to django...@googlegroups.com
Possible to push the whole code to a Github repo so someone could check out and try locally - Couldn't really figure out anything that might be going wrong by looking at this much mode?

Also, just out of curiosity, why are you using Department.objects.filter() instead of Department.objects.all() since you are anyways not passing anything to the filter.

--
Regards
Deep L Sukhwani


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/905973fa-6d90-4b45-bb69-ffcc787d2524%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages