[Answered ]-Django retrieve data from db to complete a url pattern

2👍

You can do a reverse lookup on your leaguePage to do your redirect, passing in the values you need to resolve the pattern. You’ll need to add a name to the URL pattern you want to reverse, but basically the syntax is:

return HttpResponseRedirect(reverse('my_detail', args=(), kwargs={'id' : id}))

Example URL pattern and view:

urlpatterns = patterns('my_app.views',
    url(r'^my-pattern/(?P<id>\d+)/$', 'my_action', name='my_detail'),
)

def my_action(request, id):
    #do something

Hope that helps you out.

Leave a comment