【发布时间】:2015-06-09 00:15:28
【问题描述】:
我有两个表单页面:
- 开始表格 - 输入基本信息的地方
- 添加产品表单 - 使用开始表单中的数据填充某些字段。您还可以在表格中提供更多信息。
在 urls.py 我有这个:
urlpatterns = patterns('',
url(r'^$',add_product_start),
url(r'^add_product/$', add_product),
)
这是我的 add_product_start 表单视图:
def add_product_start(request):
form = add_product_start_form()
if request.method == "POST":
form = add_product_start_form(request.POST)
if form.is_valid:
#return respose to the add_product url with request data
return render(request,'index.html',{'form':form})
这是我的 add_product 视图:
def add_product(request):
images = []
if request.method == "POST":
initial = {field:value for (field,value) in request._post.iteritems() if value}
#a bunch of other code
#point is I want to receive post data from add_product_start view and at the same time redirect to a different url, because I don't want to have the same url of two different forms.
return render(request,'add_product.html' ,{'form':form,'images':images})
我知道有类似 HttpResponseRedirect 之类的东西,但它们只是将我重定向到没有任何类型数据的页面。我想从开始表单中获取数据,对其进行验证,如果有效,将其传递给具有不同类型的第二个视图页面。
谁能帮帮我。非常感谢!
【问题讨论】:
标签: python django forms request