So I have a django project and there is one view(home view) which displays the posts of the followed users and that requires a user to be authenticated, if there is no user loged in, then the code returns a ‘AnonimousUser’ is not iterable error and I will like my code to redirect the anonymous user to the login page
Tag: django-models
Django items = order.orderitem_set.all() returning empty value for quantity
When I try and put the {{ item.product.quantity }} in it returns an empty value. The quantity value is filled in in the database. I can’t seem t pinpoint the problem. I have tried printing the quantity value but got the same results. cart.html views.py models.py If I do print(items) the result would be: Answer So quantity is a field
TypeError ‘Purchase’ object has no attribute ‘__getitem__’ [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question views.py def vendor(request,pk): current_shop = get_current_shop(request) instance =get_object_or_404(Vendor.objects.filter(pk=pk,shop=current_shop,is_deleted=False)) Answer purchases is a normal QuerySet that yields model instances when iterated over. All your other queries
Django user registration form not showing properly
I am making a Django project where there are two types of users customer and restaurant. Both can register separately. Everything is running fine except that I cannot add CSS class to password field and there are warning showing around password field which I don’t how they are coming. Models.py Forms.py soryy for bad code pasting.Just for clarification class ‘CustomerSignupform’
JSONField in Django continues to remain empty even after POST request
I have a model with a JSONField in Django. If I issue POST through the browser using Django Rest UI, the data gets entered into the model with no issues. However,when I use Python’s requests.post in my application, everything except the JSONField data stores in the model. Here is my model Here is my Serializer Here is my view Here
Template file not found Django
I am trying to make a home page of a new website via Django. My app name is ‘blog’, home page is home.html I still receive the error template does not exist when I go to http://127.0.0.1:8000/blog/home/ I made sure I added ‘blog’ to my templates in settings.py and that I added the folder templates in the main directory as
django migration is not creating all the fields from defined model class into db
Hi i am trying to generate migration but all fields are not getting created into the db. Below is my code. Answer You are putting comma after defining each field. Remove them and you are good to go!
Get value of related object by list of fields in @property
I have two model like this with following fields: I Also I have this list of fields name: And finally I want to I create this @property: But for related objects this isn’t the correct way and I got this error: ‘Profile’ object has no attribute ‘address.postal_code’ How Can I use this list for get value of field of Profile
How to open detail view in editable format as shown in admin page?
I’m trying to show the user the details they entered in an editable format as we can see in Edit: Changed the code and tried to explain the question in a better way view.py forms.py This view loads the forms as I want it to but the changes made here is not reflected in the database. Where am I going
Is it possible to make a mobile app in Django?
I was wondering if it is possible for me to use Django code I have for my website and somehow use that in a mobile app, in a framework such as, for example, Flutter. So is it possible to use the Django backend I have right now and use it in a mobile app? So like the models, views etc…