Hello
local variable 'product_list' referenced before assignment
Hello
Ive got this error... how its possible ? the 'product_list' is inside the block
Ali
Ive got this error... how its possible ? the 'product_list' is inside the block
Because except block run and then you don't have product_list You must create product_list variable in except block
Hello
To create as what ? As empty list?
Ali
Empty or false
Hello
It’s still doing the same problem.. doesn’t show the product_list. It goes to the except block
Hello
https://dpaste.org/HVXRW there are the changes
Hello
this is the template https://dpaste.org/e1Wif
Maksim
Hi! How solve this problem: ForeignKey(['users.NoName']) is invalid. First parametr to ForeignKey must be.....(AUTH_USER_MODEL)
AℤℐℤℬℰᏦ ☝️
while i < len(elem): TypeError: object of type 'SimpleRouter' has no len()
Arash
Hi. I'm learning Django and I'm using ready-made html css js templates to practice backend with Django. I have been asked a question and that is, what information should I store in the database through the models.py and what information should I store in the folders? For example, which photos from the website should I store in the database and which should I save in folders?
Koen de
Hi. I'm learning Django and I'm using ready-made html css js templates to practice backend with Django. I have been asked a question and that is, what information should I store in the database through the models.py and what information should I store in the folders? For example, which photos from the website should I store in the database and which should I save in folders?
I like to store all media in folders because that keeps my database small and I can easliy move the storage around my cloud servers. Even if you store them in a FileField or ImageField they are stored on disk too https://docs.djangoproject.com/en/4.1/ref/models/fields/#django.db.models.ImageField
Picasso
Hi! I'm a beginner in django. I'd like to know how to make my nav links render my templates properly
Hello
https://dpaste.org/HVXRW there are the changes
Please someone can help me??🙏🏻
Hello
Hey everybody! How to create a list from field that is ‘manytomany’ in specific object ?
Koen de
It’s still doing the same problem.. doesn’t show the product_list. It goes to the except block
It goes to the except block because in your sample code the variable “em” is not declared
Picasso
thanks. I just got the answer
Hello
I did it as a global on other func . This is the input of the user
Hello
So how to code if it’s not catch it as a global var?
Koen de
I did it as a global on other func . This is the input of the user
Place; import pdb pdb.set_trace() As first line after “try:” Then run your code again and check what “em” actually is.
Koen de
So how to code if it’s not catch it as a global var?
Where is “em” coming from? How is it set? Is it part of the user that is logged in?
Hello
https://dpaste.org/ba7XK this is the code
Hello
you can see it on the second fun
Koen de
you can see it on the second fun
Please try the “pdb” I mentioned to see what “em” really is at that point.
Hello
On the cmd I got :
Hello
and give me the option to write
Hello
-> user = FavoriteList.objects.get(email=em) (Pdb)
Hello
what is mean?
Koen de
Yes! That’s nice. Now, just type: em to see what “em” is.
Hello
''
Hello
empty string
Koen de
Your inside the Python Debugger now. With “c” you can continue
Koen de
Empty string, you have to find out why em is not set at that point. Maybe the initial code where you to set it is not correct
Hello
so how to keep the input that the user give me?
Koen de
It is why I do not like/use globals ;-)
Hello
There is another way?
Koen de
You can try to read the email from the request in the productlist method. Or find out why it is not set in ask_productlist. Play around with pdb https://docs.python.org/3/library/pdb.html
Anonymous
Is it ok: .prefetch_related().select_related()?
Anonymous
It works but I think there is better way to do it
Koen de
Is it ok: .prefetch_related().select_related()?
It is ok. You can use django-silk to see how many SQL queries you can save and how many processing time you can win with(out) both of them.
Elhem
Swagger does not require parameters of for login When I came to api/login view There I could find a field where I needed to send "username" and "password" For LogIn I inherit from KnoxLoginView HOW could I make Swagger require parameters and see Knox ?
Elhem
please i need help
Hello
You can try to read the email from the request in the productlist method. Or find out why it is not set in ask_productlist. Play around with pdb https://docs.python.org/3/library/pdb.html
How to call it from the func? This is var … I have more idea ! To put the email as an input to productlist and also to add the urls where it is exist . But I didn’t sucssed to move this value from one func to the other
Koen de
How to call it from the func? This is var … I have more idea ! To put the email as an input to productlist and also to add the urls where it is exist . But I didn’t sucssed to move this value from one func to the other
I do not have enough knowledge of your application, Reading through your code it seems like a wizard the user runs through. Instead of the globals you can also use “session variables” http://www.learningaboutelectronics.com/Articles/How-to-create-a-session-variable-in-Django.php
Hello
I do not have enough knowledge of your application, Reading through your code it seems like a wizard the user runs through. Instead of the globals you can also use “session variables” http://www.learningaboutelectronics.com/Articles/How-to-create-a-session-variable-in-Django.php
def ask_productlist(request): if request.method == 'POST': email = request.POST.get('email','') request.session['email_user']= email return redirect('productlist') return render(request, 'product/ask_productlist.html')
Hello
I put it like this
Hello
def productlist(request): try: pdb.set_trace() user = FavoriteList.objects.get(email=request.session['email_user']) product_list = user.favorite_product.all() except FavoriteList.DoesNotExist: messages.error(request, "There isn't exist this email adrees. Please create your favorite list") product_list=None return render(request ,'product/productlistdetails.html', {'product_list': product_list})
Hello
and when I get on the cmd pdb : request.session['email_user']
Hello
get again empty, maybe because its before?
Hello
But on the web it still don’t catch it
Koen de
You could investigate the order of the methods, which one is called before the other
Hello
The input from the user , the email
Koen de
Ok .. I try
Investigate if the email is actually set during ask_productlist too
Hello
I check , I put the pdb after when its put to see the allocate , return empty string again...
Hello
def ask_productlist(request): if request.method == 'POST': email = request.POST.get('email','') request.session['email_user']= email pdb.set_trace() return redirect('productlist') return render(request, 'product/ask_productlist.html')
Sayidbek
Hey there, how can I create sign_up function where peope sign up with raw HTML?
Hello
Ok I try thank you 🙏🏻
Anonymous
I'm unable to update my model. Like for example, if I create a model and save it and migrations it works fine. But If I add another field to model and try to make migrations an error pops up "It's impossible to add non-nullable field" How to solve this error?
Anonymous
Add null=true
Tried it but it ddnt work
Ali
Tried it but it ddnt work
Remove all records and try again If you get the error again, you can delete the database and recreate it
Koen de
Tried it but it ddnt work
What is the complete error after adding null=True then?
Anonymous
What is the complete error after adding null=True then?
Thank you, deleting the db and starting afresh works
Koen de
Still the same error
“It’s impossible to add non-nullable field” is not the complete error… But it seems you already got your solution with a fresh database
Anonymous
“It’s impossible to add non-nullable field” is not the complete error… But it seems you already got your solution with a fresh database
Ddnt try that but will try it. Not exactly, sometimes I won't want to delete and restart. I'll have to solve that error
IM~Exynos
How to create custom logs for specific function via model.
Koen de
How to create custom logs for specific function via model.
Well I like Sentry to handle my logs. But “django-db-logger” is my second best. https://github.com/CiCiUi/django-db-logger Why should you reinvent the wheel? In any other case you can create a simple Model with a textfield and report your logging there. You can use django-db-logger aa inspiration and even copy+modify their codebase as their WTFPL-license allows that.