Python Forum

Full Version: For loop in Django
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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.