Answer the question
In order to leave comments, you need to log in
Why did the form stop working after access restriction?
Can you please tell me why the form stopped working? This is a registration form, and I have restricted access to it to authorized users. After the introduction of the dispatch function, the registration stopped working (after filling in all the fields and pressing the button, the page seems to be updated and nothing is created).
At the same time, everything is fine with the first part of the cycle (where is the redirect).
class BaseRegisterForm(UserCreationForm):
username = forms.CharField(label='Имя пользователя',
widget=forms.TextInput(
attrs={'class': 'form-control',
'placeholder': 'Введите имя пользователя'}))
email = forms.EmailField(label='Электронная почта',
widget=forms.EmailInput(
attrs={'class': 'form-control',
'placeholder': 'Введите Email'}))
password1 = forms.CharField(label='Пароль',
widget=forms.PasswordInput(
attrs={'class': 'form-control',
'placeholder': 'Введите пароль'}))
password2 = forms.CharField(label='Подтверждение пароля',
widget=forms.PasswordInput(
attrs={'class': 'form-control',
'placeholder': 'Подтвердите пароль'}))
class Meta:
model = User
fields = ["username", "email", "password1", "password2"]
class BaseRegisterView(CreateView):
model = User
form_class = BaseRegisterForm
success_url = '/'
def dispatch(self, request, *args, **kwargs):
if request.user.is_authenticated:
return redirect('redirect')
return super().get(request, *args, **kwargs)
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Продолжить">
</form>
path('signup/', BaseRegisterView.as_view(template_name='sign/signup.html'), name='signup')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question