Page not found (404)

My urls.py is like below.

path('register/', PatientRegisterView.as_view(), name='register'),

My views.py code is like below

class PatientRegisterView(FormView):
    template_name = 'register.html'
    # fields = '__all__'
    form_class = UserCreationForm
    redirect_authenticated_user = True
    success_url = reverse_lazy('dashboard')


    def form_valid( self, form ):
        user = form.save()
        if user is not None:
            login( self.request, user )
        return super( PatientRegisterView, self ).form_valid( form )
    

    def get( self, *args, **kwargs ):
        if self.request.user.is_authenticated:
            return redirect('register')
        return super(PatientRegisterView, self).get(*args, **kwargs)

My reigster.html code is like below.

<form action="POST">
        {% csrf_token %}
        {{ form.as_p }}
        <input type="submit" value="Register">
</form>

But I am getting Page not found (404) error.

The Problem is the action attribute

It should be

<form method="POST" action=".">
        {% csrf_token %}
        {{ form.as_p }}
        <input type="submit" value="Register">
</form>

<form>: The Form element - HTML: HyperText Markup Language | MDN (mozilla.org)

1 Like