It was clarified that I suppose to the method instead of action in HTML form.
<form action="post">
On Mon, Sep 24, 2018 at 7:05 PM Nelson Varela <nelson.c.varela@gmail.com> wrote:
Do you have 'django.middleware.csrf.CsrfViewMiddleware' in your list of middlewares in your settings?--
On Monday, September 24, 2018 at 2:52:33 PM UTC+2, Srinivas Gadi wrote: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 %}
--Please adviseSrinivas .G
9966559383
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/6be4f994-abdf-4045-af80-da17eabdf886%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Srinivas .G
9966559383
-- 9966559383
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/CAPC7spiPsAfDXR6SfPRVpYtR50AboJoS9dEaqcwkwBQacXsBbw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment