1,665 questions
0
votes
1
answer
67
views
django_filters.Filterset with context data from FilterView
I've a LearnerInstance model:
class LearnerInstance(models.Model):
learner = models.ForeignKey(Learner, on_delete=models.CASCADE)
aim = models.ForeignKey(Aim, on_delete=models.CASCADE)
...
...
0
votes
1
answer
106
views
How to change the URL password reset domain in django?
Resetting the password in Django has four main step;
Receive email from the user
Send password reset link
Get the link and change the password from the user side
Register new password successfully
I ...
0
votes
1
answer
44
views
Problem with testing Messages in Django 5 CreateView
I am writing unit tests of ebook catalog applications in Django 5. The book creation page uses the built-in CreateView. The class code looks like this:
class BookCreate(SuccessMessageMixin, ...
0
votes
2
answers
84
views
django modify FormView fields before form validation
Is there a proper way to modify the form fields before validating the data on a Class Based FormView. More specifically a CreateView. Is necessary to use Class Based views 'cause I'm throwing in a ...
0
votes
1
answer
43
views
In django class base view whenever I logged in, my user log in successfully but get this error page:Page not found (404)
I tried class base view in my blog website authorlogin. Every time I log in though, my author gets logged, but get a page of error. I have just convert login into class-based view but my author ...
0
votes
0
answers
32
views
Keep input values on exception in django form
If the python function "is_valid" has an exception, how do I keep the input values that were entered on the django form?
I did search, maybe I don't know a better way to search.
If there is ...
0
votes
0
answers
34
views
Why is django class-based_view not seeing my uploads?
class MultipleFileInput(forms.ClearableFileInput):
"""
Work around for `widget=forms.ClearableFileInput(attrs={'multiple': True})`
>> `widget=MultipleFileInput(attrs={'...
3
votes
1
answer
1k
views
How to effectively use PUT and DELETE HTTP methods in Django Class-Based Views?
I'm setting up a CRUD system with Django, using Class-Based Views. Currently I'm trying to figure out how to handle HTTP PUT and DELETE requests in my application. Despite searching the Django ...
-1
votes
1
answer
55
views
if user is already logged in do not show sign in form
I have used User Creation Form for user registration.
class UserSignUpView(SuccessMessageMixin, FormView):
form_class = UserCreationForm
success_url = reverse_lazy('login')
template_name = ...
1
vote
1
answer
32
views
My Class Based View(Django) code cant recognize id from SQL database
I tried to make a training project with forms. I wanted to create a code for upgrading feedbacks in the form by Class Based Views.
views.py
class UpdateFeedbackView(View):
def get(self, request, ...
1
vote
2
answers
151
views
`UNIQUE constraint failed at: pharmcare_patient.id` in my pharmcare app
I have a Django app in my project I am currently working on called pharmcare, and I kind of getting into a unique constraint issue whenever I want to override the save() method to insert/save the ...
2
votes
2
answers
4k
views
Problem with Django class-based LogoutView in Django 5.0 [duplicate]
I used Django class-based login and logout views by "django.contrib.auth.urls", login feature works correctly, but when logging out via the link "http://127.0.0.1:8000/accounts/logout&...
0
votes
1
answer
138
views
Update view with django-formtools
I implemented django-formtools SessionWizardView with a navbar, so I can jump between steps if I want to update existing instances.
My problem is, if I want to edit an instance I have to submit all ...
1
vote
1
answer
166
views
How to pass self.request data in django form?
I want to pass self.request data in the form class. I can access it in View, but unable to access it in form class.
class AttendanceCreateView(LoginRequiredMixin, CreateView):
model = Attendance
...
0
votes
1
answer
116
views
How to add permissions based on group membership on Django Rest Framework Class-Based Views?
Thank you for your time.
The following code is a class-based with the method named get_permissions() which purpose is to allow only the authenticated users to make POST,PUT,DELETE and PATCH requests:
#...
1
vote
1
answer
39
views
Django Class Based View: Deny access to future dates unless logged in
I have a Promotion model containing a published_date field. I would like to restrict access to future promotions to logged in users who are 'previewing' their promotion.
class Promotion(models.Model)...
0
votes
1
answer
42
views
Django simple ModelForm not showing on page (I'm using class based-views), what could be the problem?
I'm trying to build a form to use it as a filter for my project search page, but the {{form}} shows nothing. Here is how everything is set up:
The model I'm trying to use from models.py
class Exemplar(...
0
votes
1
answer
68
views
Prepopulate ModelForm in FormView with data of another form sent to the by POST method -Django
I'm trying to prepopulate a django FormView fields with data of another form (prepatory for a meeting minute creator).
I made an project simplifiying and reproducing the error for better comprehension ...
0
votes
0
answers
23
views
Redirection in Class Based Views Doesn't Completly Work
views.py:
class LoveLetterCreateView(LoginRequiredMixin, CreateView):
model = LoveLetter
fields = '__all__'
success_url = reverse_lazy('login') # NOT WORKING
class SignUpView(CreateView):
...
0
votes
1
answer
72
views
my generic view inherited from CreateView in django does not show model fields to fill out when I run my django project
I create an app in django named 'sampleapp' then in models.py I define my model as follows:
from django.db import models
from django.urls import reverse
class Employee(models.Model):
first_name = ...
0
votes
1
answer
63
views
Django View - How to Efficiently Filter Combined Querysets from Multiple Models?
I have a Django view that combines and sorts querysets from three different models (Event, Subject, and Article) to create a feed. I'm using the sorted function along with chain to merge the querysets ...
3
votes
4
answers
3k
views
drf-spectacular swagger authentication
I'm digging google for 3 hours right now, and can't find solution for my problem. I moved in my project from drf-yasg to drf-spectacular because openapi +3.0 isn't supported in yasg. I want to have an ...
0
votes
1
answer
40
views
ProfileUpdateView: Generic detail view ProfileUpdateView must be called with either an object pk or a slug in the URLconf
I tried to make a cbv class to generate a profile update function. I use username in URL, but there is always a mistake
AttributeError at /edit_profile/apani
Generic detail view ProfileUpdateView must ...
0
votes
0
answers
43
views
Chained select inputs using Django CBV
I am trying to create an interface for a teacher to set homework tasks. This homework includes a student, a chapter, and questions belonging to a selected chapter. Therein lies my problem, I would ...
0
votes
1
answer
52
views
I cannot pass the values between the methods in classBasedView
I need to pass the bundle and the message values to get_context_data() method, but I cannot figure out how to do it.
In this instance the form is valid when I pass it (I can add the better error ...
1
vote
1
answer
153
views
How to return existing matching record for Django CreateView
I use a regular generic.edit.CreateView of Django to create an object according to user input. The MyModel has an UniqueConstrait so the creation would fail if the new object happens to match an ...
0
votes
1
answer
1k
views
How to implement async view through class-based view(CBV) in Django
An AssertionError occurred while trying to operate asynchronous view as class-based view in django(CBV)
The python code i wrote is as follows.
urls.py
from django.contrib import admin
from django.conf....
0
votes
1
answer
321
views
Django Docstring implementation
I have a Django project, I'm putting comments and google-style docstrings for better understanding. My question is, Is it okay to mention other methods or classes in a docstring within a function or a ...
0
votes
2
answers
130
views
Django: How to reference a context variable created in one class-based view from another class-based view
In the simplified example below, how do I reference the context variable "Elephant" (created in the class Lion) from inside the class Leopard?
I have researched and tried a number of ways, ...
0
votes
1
answer
292
views
How to pass user submitted form data into the success_url in django
I am trying to pass the user submitted form data into the url kwargs. As of now I am directely returning the redirect response within the form_valid methoad of django's class based views.
class ...
1
vote
1
answer
69
views
CreateView creates user but doesn't log user in
I am trying to make a class-based registration view equivalent of my old function based registration view. When I register as a new user, a user is created but is not logged in after registration, and ...
0
votes
1
answer
318
views
How to get the detailed page by slug and not id in Django Rest Framework class based views
I am building an API using Django Rest Framework. I have the /api/localities endpoint where all of the objects on my database are displayed.
Now I want to create the endpoint for a single page of a ...
0
votes
1
answer
44
views
Null is passed to todos_id while submitting form eventhough i've changed it
this is my view which is createview and i've used custom form and send current user id to the form
class createToDo(CreateView):
success_url = 'home'
form_class = ToDoForm
...
0
votes
1
answer
58
views
Python (+Django) : use @property in success_url KO . while using it with get_success_url is OK (class based view)
I found a workaround for my issue but I need to know why the first above case doesn't work.
I need to pass a parameter (reman_pk) to my view but when I try :
class RepairCreateView(LoginRequiredMixin, ...
0
votes
1
answer
34
views
Django: Querying Foreign Keys
I have two models Book and Review,
models.py
class Book(models.Model):
title = models.CharField()
class Review(models.Model):
rating = models.IntegerField()
content = models.TextField()
...
1
vote
2
answers
666
views
Django: Unable to Apply Function View Decorator to Class Based View
I'm migrating from regular function based views, to class based views. One of the things that I couldn't migrate were the decorators I used. The decorator in question checks if the credentials of the ...
0
votes
1
answer
283
views
Exception Value: 'CustomUser' object is not callable | CustomUserModel
I am trying to create a custom user model. The model is working fine in command prompt and I am able to login to admin panel as well. I can access Login page as well. But when I try to access the ...
0
votes
1
answer
2k
views
How to run long running task behind the scence in django class based view?
I want to run long running task in Django class based Redirectview. Before this running task to complete I want to return template. Here is my code.
I try with this code.
class Redirect_to_page(...
1
vote
2
answers
67
views
How can I skip pk in url while redirecting to another url with generic RedirectView in Django?
I am trying to delete a record after displaying it with DetailView and redirecting to the list page again.
view.py
...
class DailyRecordDeleteConformationView(RequiredBasicDetailsAndContextMixin, ...
1
vote
1
answer
36
views
Why individually rendered form fields not posting in Django?
I have a class based UpdateView that works fine if I render the form as {{ form.as_p }}. It updating the values, but looks bad.
If I try to render the fields individually it does not updating the ...
0
votes
1
answer
44
views
Attibutes are 'disappearing' from CBV. Django
I am trying to build CBV with class View parent. This view takes slug of object and find that object between two django models. The functions from services.py was doing a lot of DB queries, so, I ...
2
votes
0
answers
73
views
how to use update_or_create in django createview
I want to update_or_create object by django CreateView.
my class problem is update object but create duplicate of updated object
class CardexCreateView(LoginRequiredMixin, CreateView):
model = ...
-1
votes
1
answer
47
views
How change a function based view into a class based?
I want to write a category detail view in order to do so i want to change this function based view
def CategoryView(request, cats):
category_posts = Post.objects.filter(category=cats.replace('-', ' '))...
0
votes
1
answer
65
views
Django CBV: How come my child method is not overriding my parent method?
I'm pretty new when it comes to python classes / django CBVs. I'm trying to have a method (print_test) from my child class override my parent class, but I can't get it to work. What am I doing wrong?
...
1
vote
2
answers
100
views
Django CBV: How to subclass scattered parts of code from the parent class
I'm trying to jump from the world of FBV to CBV, but running into an immediate problem...which i'm sure must be pretty common and solvable and I just don't know how...
I'm inheriting the general View ...
0
votes
1
answer
251
views
User can't login because of "Invalid password format or unknown hashing algorithm."-Django
I'm learning Django and tried to write my own custom user model. I'm not using DRF and serializers and stuffs I have no idea about :)
I am using createView to create users but I can't login because &...
0
votes
0
answers
50
views
Django detail view not rendering static files
Hello my I have a Django project which works fine but the problem I usually get is from my Detail View, it does not render statics files. And when I check the output from my terminal I see that my ...
1
vote
1
answer
204
views
Reuse test_func for UserPassesTestMixin in Django
Suppose I have 2 view classes
class View1(LoginRequiredMixin, UserPassesTestMixin, View):
def get(self, request, *args, **kwargs):
#Do something and render a page
def test_func(self):
...
0
votes
1
answer
194
views
Django updateview (cbv and fbv) to upload multiple files not working
I am trying to upload files (single and multiple) with an UpdateView via an update template but I keep getting a 'This field is required' error when I submit, and the files aren't uploaded, of course. ...
1
vote
1
answer
433
views
How to redirect user from registration page to profile if user is already registered?
I am using Django class-based views for my project and trying to redirect user from registration view if he is already authenticated. I've done it already with LoginView and it was pretty simple and ...