Issue
After i ran a view without a template, id like to reverse back to the previous view. However this view had a dynamic part in it, and now i cant figure out how i could pas that argument with my reverse:
My urls:
url(r'^building/(?P<building_id>\d+)/$', views.building, name='building'),
url(r'^building/upgrade/(?P<building_id>\d+)/$', views.building_upgrade, name='building_upgrade'),
My view:
@login_required
def building_upgrade(request, building_id):
building = get_object_or_404(Building, pk=building_id)
if building.town.user != request.user:
return HttpResponseRedirect(reverse('index'))
create_upgrade(building)
return HttpResponseRedirect(reverse('building'))
How can i send the building_id back with the reverse, so it knows what url to load?
Solution
reverse('building', kwargs={'building_id': building_id})
Answered By - Daniel Roseman
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.