Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
For loop in Django
#1
Hi all
For loop is not working in my CMD when do operations on DB tables in Django
import random

>>> import random
>>>
>>> for vege in veges:
... vege.recipe_view_count = random.randint(10, 100)
... vege.save()
...
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'veges' is not defined
>>> recipes = Recipe.objects.all()
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'Recipe' is not defined
>>>

I getting this error.
Larz60+ write Mar-19-2024, 10:08 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
This error occurs because you're trying to iterate over a variable named veges, but it's not defined anywhere in your session. You probably meant to iterate over the Recipe objects instead.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,350 Jun-30-2019, 12:21 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020