Whenever I run this, Exception Value: name ‘current_user’ is not defined; error is raised. I am not getting where i am doing the mistake as I m new in django programming. Please help me fetch the data Answer It looks like you will be getting that problem from showproduct(request) because you don’t define current_user in that method before calling it.
Tag: django
Django order a query by instance of ManyToMany
I have a model A with a ForeignKey to B: A ManyToMany relationship with an extra field that weight any B and C relation: And I need to order the A model (A.objects.filter(…)) using the weight of B2C for a given instance of C. For only one A instance I can do : But I don’t know how to do
how to register a tag in HTML django to make a string lowercase?
I have a python list, iterated over to display a bullet point list on a web page. I want to make each entry in the list lower case, but still keep the original case for what get’s displayed. I’m getting the following warning via Django below: My html: thanks Answer ref: https://docs.djangoproject.com/en/3.2/ref/templates/builtins/
how to return nested json using django rest framework
I am trying build a REST API using django. here is my models.py and serializers.py. models.py serailizers.py Here is my api – http://127.0.0.1:8000/api/city/Sidney/. I am trying to fetch data by city name. I am getting the json in below format. But i want the json in below shown format – i am not getting what change needs to be done
Django Error: Field ‘id’ expected a number but got ‘list’
I have an app with 2 models and I’m trying to create a List View and a Detail View. The list view worked fine, but when I created the detail view the list view stopped working and it’s prompting me with this error: “Field ‘id’ expected a number but got ‘list’. Models.py views.py urls.py and my templates: Answer Your pattern
Is there a way to check if some value is IN request.session.name?
Can anybody clarify, please? I got a Cart object in request.session I want to check if request.session.cart CONTAINS item.id as a key from template I know that game.id is FOR SURE in that cart object, but template doesn’t react on that. I HAVE a context processor added UPDATE: SETTINGS.PY Template and session data game.id is seen on the picture (actual
Deploying heroku – Push failed
I need some help to solve this. I don’t have much experience with Heroku, this is my first time doing it but I need to deploy some app really quickly. I’ve tried to disable collectstatic with heroku config:set DEBUG_COLLECTSTATIC=1 -a name_of_app But it haven’t made any change. Can anyone help me, please ? Here are logs: Answer in your Heroku
Check file extension in Django FileField
I need to run a different code depending on the extension of the file. This is a simplified version of the model: This is the part of the view that I have the problem: I don’t know how I should write this last condition above. With this version above, I get the error: The ‘python’ engine cannot iterate through this
Django(djongo) can’t connect to MondoDB Atlas after Heroku deployment
I managed to get it working locally (different cluster, separate settings.py), but not after when deployed to Heroku. Heroku – automatically adds DATABASE_URL config var with a postgresql, and I cannot remove/edit it. MongoDB Atlas – I’ve set the MongoDB Atlas cluster to allow IPs from everywhere. And the password has no funny characters. django production settings.py I ran migrate
How can I get a value from other model, based in other value from that same other model?
How can I get the proper “sumvalue” in the example? (which I only know how to represent in SQL): Answer In your case, c is not a field, but a property. You can call it on an instance: Now for what you’re trying to do, I really recommand you use annotate. You then have an additional field in your query