Reputation: 39
All the registration form is running fine.The problem is on the redirect of function addUser.I am getting the error on redirect.I am trying to save the data in the admin panel but i am stuck on this.
from django.shortcuts import render,redirect
from django.http import HttpResponse
from .forms import RegistrationForm
from .models import RegistrationData
#from django.contrib.auth.form import UserCreationForm
# Create your views here.
def index(request):
return render(request, "Yatri/home.html")
def SignUp(request):
context= {"form":RegistrationForm}
return render(request,"Yatri/register.html",context)
def addUser(request):
form=RegistrationForm(request.POST)
if form.is_valid():
register=RegistrationData(username=form.cleaned_data['username'],
password=form.cleaned_data['password'],
email=form.cleaned_data['email'],
phone=form.cleaned_data['phone'],
register.save()
return redirect('index')
I expect the username,password,email and phone to be saved in database but i get the error the site cant be reached.
Urls.py
from django.contrib import admin
from django.urls import path, include
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('Signup/',views.SignUp,name='Signup'),
path('addUser/',views.addUser,name='addUser'),
]
Upvotes: 0
Views: 89
Reputation: 398
missed parentheses in addUser view:
def addUser(request):
form=RegistrationForm(request.POST)
if form.is_valid():
register=RegistrationData(username=form.cleaned_data['username'],
password=form.cleaned_data['password'],
email=form.cleaned_data['email'],
phone=form.cleaned_data['phone'],)
register.save()
return redirect('index')
Upvotes: 1