Reputation: 23322
How do you use the reverse()
from django.core.urlresolvers.reverse
at the command line? I want to debug what is going wrong in my Django application. I am not sure if it is happening at the views
, the urls
or the html
template page.
I have the command line open in the directory of the project, but it doesn't recognize my commands (which I am borrowing from the Django-Project page).
Upvotes: 0
Views: 1123
Reputation: 1770
If your urls.py
file consists on something like this:
urlpatterns = patterns('',
url(r'^$', 'views.recent', name='recent'),
url(r'^recent/(?P<page>\d+)$', 'views.recent', name='recent')
)
using python manage.py shell
in your project directory you do the following:
>>> from django.core.urlresolvers import reverse
>>> reverse('recent')
'/recent'
you can pass specific parameters 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 reverse for your particular version of Django.
Upvotes: 3