我创建了一个django项目。这个django项目分为两个应用程序,即用户和普通应用程序。我在用户应用程序中有一个方法,允许用户提交一个表单,该表单将创建一个新的Django用户。提交表单和进程后,我想将用户重定向到常用应用程序中的测试页面,并显示一个说明测试页面的html模板。一切正常,表格正在处理,重定向正在发生。我知道这个,因为url更改为预期的url,它将显示html测试页面。出于某种原因,即使URL正在转移到正确的URL,显示的html模板实际上是注册表单html模板而不是正确的模板。
以下是常见应用的代码:
views.py
# testing method
def test(request):
return render(request, 'common/test.html')
urls.py:
urlpatterns = [
url(r'^test/$', views.test, name='test'),
]
的test.html:
{% extends "base.html" %}
{% block standard %}
<p>testing page</p>
{% endblock %}
这是来自用户应用的重定向:
这是在创建用户后的注册def
return redirect('test')
这是整个注册方法:
# have a user signup and create his account
def Signup(request):
# check to see if form is submitted
if request.method == "POST":
# grab the form and information
form = SignupForm(request.POST)
# validating form
if form.is_valid():
# grab the form content
cd = form.cleaned_data
username = cd['username']
password = cd['password']
verify = cd['verify']
email = cd['email']
# check if passwords match
if password == verify:
# create safe passwords
secure_password = make_password(password)
# save username in sessions
# request.session['username'] = username
return redirect('test')
else:
# redirec to original forms
message = "Passwords did not match"
# users form
form = SignupForm()
# everything required for the template
parameters = {
'message':message,
'form':form,
}
# display html template
return render(request, 'user/Signup.html', parameters)
else:
# the signing up form
form = SignupForm()
message = "Please fill out the entire form"
# everything that needs to be passed to html template
parameters = {
'form':form,
'message':message,
}
# render the template
return render(request, 'user/Signup.html', parameters)