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:
- how do I form the url regex to recognize the list
- how do I concatenate the list with the rest of the url in the HttpResponseRedirect so that it will read
- how do i pass the list in the second view (I vaguely remember using * last time I did this but I couldn’t find any useful reference material)
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:
and then no need for regex in the urls