Thursday, November 23, 2017

How do I make my form send a POST request to a specified view?

My page has a registration form at `"/login_register/"`. I want the form to send a POST request to `"/register/"`. Here's my code so far.

`urls.py`:
url("^login_register/$", views.login_register, name="login_register"),
url("^register/$", views.register, name="register"),


`views.py`:
def login_register(request, template="pages/login_register.html"):
 
'''
 Display registration and login forms
 '''

 registration_form
= RegisterForm()
 
return render(request, template, {"registration_form": registration_form})


def register(request):
 
'''
 Process user registration
 '''

 
if request.method=="POST":
   
# Some code here


`pages/login_register.html`:
 # For this example, I only include the registration form's HTML
 
<h2>Register</h2>
 <form method="post">
 {% csrf_token %}
 {{ registration_form.as_p }}
 <button type="submit">Register</
button>
 
</form>


When I hit "Register" on the form, my browser sends a POST request to "login_register/". I want it to send a POST request to "register/". How do I do this?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/72030063-8482-4723-9f2c-b25b17656a43%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment