I have two form pages:
我有两个表单页面:
- Start Form - where you input the basic information
- 开始表单 - 您输入基本信息的位置
- Add product form - uses data from start form to populate some fields. And there you can also give more information in the form.
- 添加产品表单 - 使用开始表单中的数据填充某些字段。在那里,您还可以在表单中提供更多信息。
In the urls.py I have this:
在urls.py我有这个:
urlpatterns = patterns('',
url(r'^$',add_product_start),
url(r'^add_product/$', add_product),
)
This is my add_product_start form view:
这是我的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})
And this is my add_product view:
这是我的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})
I know there is something like HttpResponseRedirect but they just redirect me to the page without any type of data.I want to get the data from the start form, validate it, and if valid pass it to the second view with a different page.
我知道有类似HttpResponseRedirect的东西,但他们只是将我重定向到没有任何类型数据的页面。我想从开始表单中获取数据,验证它,如果有效则将其传递给具有不同页面的第二个视图。
Can someone please help me. Thank you very much!
有人可以帮帮我吗。非常感谢你!
1 个解决方案
#1
1
The best way is using the form wizard https://docs.djangoproject.com/en/1.7/ref/contrib/formtools/form-wizard/
最好的方法是使用表单向导https://docs.djangoproject.com/en/1.7/ref/contrib/formtools/form-wizard/
#1
1
The best way is using the form wizard https://docs.djangoproject.com/en/1.7/ref/contrib/formtools/form-wizard/
最好的方法是使用表单向导https://docs.djangoproject.com/en/1.7/ref/contrib/formtools/form-wizard/