Home>
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')
else:
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" >
{{user_form}}
{% csrf_token%}
<
p >
<
input type= "submit" value= "Create my account" >
<
/p >
<
/form >
{% endblock%}
Thanks in advance
added to the question
spfxd2021-12-30 10:09:58You 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:03thanks, did not notice
spfxd2021-12-30 10:36:39Related questions
- python : Data not being pushed into database from Django form
- python : Database image not showing in Django project
- python : Django. Using ldap authorization and user groups in different AD domains
- python : mapping to a specific user group in Django 4
- python : cannot import name 'url' from 'django.conf.urls' when working with Django 4.0.1
- python : Try using "django.db.backends.XXX" where XXX is one of:
- python : unable to establish connection between my django project and mongodb database (deployed locally)
- Python and Django version compatibility for an existing project
- python : Pull data from different tables django
- python : Django and ForeignKey
Show the template code that displays this form
andreymal2021-12-30 10:02:50