Monday, September 24, 2018

When I click on submit button on login page, its redirecting to an random csrf token page in django


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 advise

--
Srinivas .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/CAPC7spgu3xReK%2B0S26rg-9cq3bF1nfwmMiePT6RnbJ73DBi%2Bjg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment