How to use reverse () from django.core.urlresolvers.reverse

How do you use reverse() from django.core.urlresolvers.reverse on the command line? I want to debug what happens in my Django application. I'm not sure if this happens on the views , urls or html template page.

I have a command line open in the project directory, but it does not recognize my commands (which I borrow on the Django-Project page).

0
debugging django
Mar 03 '14 at 9:43
source share
1 answer

If your urls.py file consists of the following:

 urlpatterns = patterns('', url(r'^$', 'views.recent', name='recent'), url(r'^recent/(?P<page>\d+)$', 'views.recent', name='recent') ) 

using python manage.py shell in the project directory do the following:

 >>> from django.core.urlresolvers import reverse >>> reverse('recent') '/recent' 

you can pass certain parameters by passing a list as args or a dictionary as kwargs

 >>> reverse('recent', args=[1]) '/recent/1' >>> reverse('recent', kwargs={'page': 2}) '/recent/2' 

check the doc on the way back for your specific version of Django.

+2
Mar 03 '14 at 9:59
source share



All Articles