我有两个表单页面:
在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的东西,但他们只是将我重定向到没有任何类型数据的页面。我想从开始表单中获取数据,验证它,如果有效则将其传递给第二个不同类型的视图页。
有人可以帮助我。非常感谢你!
答案 0 :(得分:1)