在Django项目的views.py上获取错误“重定向”

时间:2019-05-31 10:26:54

标签: html django python-3.x django-2.1

所有注册表格都运行良好。问题出在addUser函数的重定向上。我在重定向时遇到错误。我试图将数据保存在管理面板中,但我坚持这样做。

 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')      

我希望将用户名,密码,电子邮件和电话保存在数据库中,但出现无法访问该站点的错误。

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'),
]

1 个答案:

答案 0 :(得分:1)

addUser视图中缺少括号:

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')