Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django reverse to dynamic id

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?

like image 976
Hans de Jong Avatar asked Jan 20 '14 17:01

Hans de Jong


1 Answers

reverse('building', kwargs={'building_id': building_id})
like image 126
Daniel Roseman Avatar answered Sep 22 '22 03:09

Daniel Roseman