I have a list in one view that I would like to pass to another view to be parsed. This is what I currently have. The views:
def view1(request):
if request.method=='POST':
list = request.POST.values()
HttpResponseRedirect('/urls/'+ str(list))
def view2(request, *list):
#do something with list
the urls:
urlpatterns = patterns('',
url(r'^urls/$', views.view1),
url(r'^urls/(?P<list>[-/\w]+)$', views.view2),
)
so the questions are:
EDIT: At the broader level I have a template and view which provide a list of objects in a form. Each object is selected by a checkbox. I have a second view and template that displays data for the selected objects from the first view. I would like the number of objects selected to not be finite or limited but that may not be an option.
As Brandon suggested, posting to the second view was a usable solution. Something along the lines of:
def view2(request):
if request.method == 'POST':
page_list=request.POST.values()
else:
HttpResponseRedirect('/urls/')
and then no need for regex in the urls
I would like the number of objects selected to not be finite or limited but that may not be an option.
It definitely is an option. Capture everything post the certain word as a single reg-ex and parse it to different "tags" within your view.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.