【发布时间】:2017-09-12 15:58:21
【问题描述】:
这是我的 django 应用程序的 views.py 的 sn-p。我使用 modelform 创建了一个表单。 models.py 有一个类用户,它有一个属性用户名。我想将注册页面重定向到“重定向”视图,但我还想传递在我们点击表单上的提交按钮并且数据存储在实例“new_form”中之后获得的用户名。
def registration(request):
if request.method=='POST':
form=userForm(request.POST)
if form.is_valid():
name=form.cleaned_data['username']
new_form=form.save()
return HttpResponseRedirect(reverse('redirect'))
else:
form=userForm()
return render(request,'student/registration.html',{'form':form})
我的 redirect.html 看起来像这样。
<h1>You have signed up.</h1>
<p>hello {{field.name}}</p>
但问题是在你好之后没有显示名称,这很明显,因为我没有通过反向('redirect')传递任何东西。那么我该怎么做呢?我的redirect.html 也有问题吗?
【问题讨论】: