Django ModelForm has no model class specified, Although model in Meta class is set to a model

Error is “ModelForm has no model class specified.” code code code The error is occurs when I’m trying to create a new user form (user_form = UserForm()). Although in my meta class I set models to the User model imported from django.contrib.auth.models. Error Info Picture Answer I think your spellings in your forms are wrong could you try to correct :Changes Meta() to Meta: then models to model

Django: def save() in

I’m trying to add the save-function inside my, but it seems I’m doing something wrong. The user has to type the first- and last-name. Without him or her entering any more data, another field inside my should be filled with a combination from these fields. Is this even possible? Thanks for all your help. Have a nice weekend! Answer Please don’t. This is redundant data. It turns out that keeping data in sync, even on the same database is more challening than it might look at first sight. Django has furthermore several functions like .update(…) [Django-doc] to

Passing an html element from anchor tag to django view

I would like to know how i can pass the html link element as a string into a django view and have the information rendered on that specific view. to be clear: I have this In html A django view rendered the items from a list and each item would ideally be clickable and the specific item would be passed into this view: my reads as : The problem I think may be that the click action is not actually passing the value into the function based view and I am not sure how to work around this easily.

How can I remove the upper array list from the list of dictionaries?

I’ve a list of dictionaries and want to get rid of the external list array. Take into consideration the array below, My serializer looks like, and the view definition is, Answer You can use the index of list to refer to the inner dictionary and omit the outer bracket. The below is the output of a[0]:

Why am i getting NoReserverMatch at /?

I am new to Python and trying to develop a simple blog application.I am getting NoReverseMatch at / error while trying canonical url. Tried different solution to fix this but i am getting help for django versions which are old. Please help me with a solution for updated Django version. ERROR: Reverse for ‘post_details’ with arguments ‘(2020, ’08’, ’15’, ‘indian-software-industry’)’ not found. 1 pattern(s) tried: [‘blog/(?Pd{4})/(?Pd{2})/(?Pd{2})/(?P[-w]+)/$’] This is my This is my (used for reverse url) This is my post_list.html Answer This is old method to for routing a URL In DJANGO 3.1 this method is used for

Django Rest Framework With Only Function Response

I just want to make a simple API with DRF. The API going to get a “keyword” from URL, and that “keyword” will go to a function. And function response is going to be API response. Simple Example: RESULT: It’s all easy. How can I make this? I read the doc but every example is making with Models, serializers etc. I don’t have any models. I have only a function and the response data. Thanks. Answer You’ll want a bare APIView if you want to use DRF’s permissions and content type negotiation system yet still keep things simple:

Django ajax: in call does not make any changes

So I made this ajax view for my user model I extends my user model with an Integerfield of notification, but when I call the ajax it does not give +1 to my notification model, does anybody know what is going on? my and my ajax call my user profile model Answer So, change url: Then, change the view function: Then, in your ajax call in the template, change the url to: /ajax/new_notification/{{ user.username }}

How to fix TemplatesDoesNotExist error even after BASE_DIR has been Joined with templates in

Image 1- Error I notice Exception Value: registration/login.html , I don’t even have that in the templates, instead, i have sign-in.html, I have no idea why it mentioned login.html. Please see my templates folder below as image 3-Templates. I’m trying to fix the above error. My project path looks like Image 2- project path Image 3- Templates The image 2 above shows that my templates folder is located in foodtaskerapp folder In the I have added ‘DIRS’: [os.path.join(BASE_DIR, ‘templates’)], in the TEMPLATES section. I think there is an error because before we can get to templates from BASE_DIR we

How to make one dropdown close when clicking another dropdown

I have 2 href links in one page and on click the href opens. But when I click the other href (without closing the first one) the first one stays open. How can I solve this? At first I tried to only open and close the dropdown with CSS, but that got really messy because of the two buttons. Now I can open both buttons and close them when I click oudside of the button-area or on the button itself again. But it doesn’t close when clicking the other button. I imagine this isn’t a hard thing to solve but

How to stop having anonymous user in django

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 if the person is on the home view. After some investigation I realized that this can be done with a custom middleware but I dont know how to do it so currently that middleware just prints if a user is