When I clock on the login page, it supposed to save the data in DB but instead URL being redirected to csrf token page.
url.py
from django.conf.urls import url
from . import views
from django.contrib.auth.views import login, logout
urlpatterns = [
url(r'^$', views.home),
url(r'home',views.home, name='home page'),
url(r'login',login,{'template_name':'section/login.html'}),
url(r'logout',logout,{'template_name':'section/logout.html'}),
url(r'register',views.register, name='register')
] views.py
def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid:
form.save()
print('data has been saved')
return redirect('section/home')
else:
form = UserCreationForm()
args={'form':form}
return render(request,'section/reg_form.html',args)
reg_form.html
{% extends "base.html" %}
{% block body %}
<br><br><br>
<form action="post">
{% csrf_token %}
{{ form.as_p }}
<button type='Submit'>Login</button>
</form>
{% endblock %}
<form action="post">
--
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...@googlegroups.com.
To post to this group, send email to django...@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/6be4f994-abdf-4045-af80-da17eabdf886%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.