When submitting a form on the site, it redirects me to a non-existent page. The registration form is located on the page with the address /% 2Faccounts /reg, when the form is submitted, it sends me to /% 2Faccounts. This address is not mentioned anywhere.

Content of viwes.py

def reg (request):
    if request.method== 'POST':
        user_form= UserRegistrationForm (request.POST)
        if user_form.is_valid ():
            # Create a new user object but avoid saving it yet
            new_user= user_form.save (commit= False)
            # Set the chosen password
            new_user.set_password (user_form.cleaned_data ['password'])
            # Save the User object
            new_user.save ()
            return render (request, 'home.html')
        user_form= UserRegistrationForm ()
    return render (request, 'registration /reg.html', {'user_form': user_form})

contents of reg.html

{% extends "base.html"%}
{% block content%}
form action= "." method= "post" >
        {% csrf_token%}
p >
input type= "submit" value= "Create my account" >
/p >
/form >
{% endblock%} 

Thanks in advance

Show the template code that displays this form

andreymal2021-12-30 10:02:50

added to the question

spfxd2021-12-30 10:09:58

You have specified a dot in action, which indicates the current "folder", and the current "folder" is /% 2Faccounts -that's why the form is sent here. Remove the action attribute altogether, it is not needed here

andreymal2021-12-30 10:27:03

thanks, did not notice

spfxd2021-12-30 10:36:39