Is it possible to get a variable in a URL to pass to a view. For example. I have a location table with many locations. If I click a location it goes to a details page of that location. The location ID gets added to the URL. I then have a link to another page/view but want to reference the location id in the next view.
urls.py:
url(r'^locations/get/(?P<location_id>\d+)/$', 'assessments.views.location'),
url(r'^locations/get/(?P<location_id>\d+)/next_page/$', 'assessments.views.next_page'),
view.py:
def location(request, location_id=1):
return render_to_response('dashboard/location.html', {'location': Location.objects.get(id=location_id) })
def next_page(request):
loc = Location.objects.get(id='id of that location')
next_page()- location_id or some other one?next_pagetakes exactly the samelocation_idargument as the originallocationfunction does, so you can use it in exactly the same way.