Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8410233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:07:27+00:00 2026-06-10T00:07:27+00:00

In Understanding django.shortcuts.redirect I started a thread about reverse and redirect_to . I still

  • 0

In Understanding django.shortcuts.redirect I started a thread about reverse and redirect_to.

I still have some problems understanding how reverse works when the first parameter is a string. I read https://docs.djangoproject.com/en/1.4/topics/http/shortcuts/#django.shortcuts.redirect many times and the corresponding part with reverse. But I am still getting a NoReverseMatch exception.

In my ROOT_URLCONF I have

urlpatterns = patterns('',
    url(r'^$', redirect_to, {'url': '/monitor/'}),
    url(r'^monitor/', include('monitor.urls')),
)

In monitor.urls I have

urlpatterns = patterns('monitor.views',
    (r'^$', 'index'),
    (r'^list', 'listall'),
)

and in monitor.urls I’ve defined code for both functions, index and listall. In listall I added the following lines:

def listall(request):
    <more code goes here>
    print "reversing 1 index: %s " % reverse(index)
    print "reversing 2 index: %s " % reverse('index')
    render_to_response("monitor/list.htmld", params)

If I visit localhost:3000/monitor/list then I can see

reversing 1 index: /monitor/ 

and nothing else, the second reverse raises an exception. Why? What am I missing?

I tracked it down to djangos code django.core.urlresolvers.callable and django.core.urlresolvers.get_mod_func. get_mod_func seems to expect something like “a.b”, thats why in callable the very first line returned “index” for func_name but an empty string for mod_name. I changed my second line to

    print "reversing 2 index: %s " % reverse('monitor.views.index')

and it worked as intended. So, why do I need to call reverse with the full module and function name (when I use strings) and the documentation doesn’t? What am I missing?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:07:29+00:00Added an answer on June 10, 2026 at 12:07 am

    I’m not sure what part of the documentation you’re hung up on, but reverse‘s first parameter is some identifying method of getting to a view: it can be either a urlpattern name, a full dotted path to the view, or the view itself

    So, based on your example, the first method is out because you didn’t define a name for your urlpattern. Your first try, reverse(index) worked because you literally passed it the view. Your second try, reverse('index'), doesn’t work because it need the full import context, i.e. 'monitor.views.index'. The difference between the two is that when it’s a string, Django must interpret that string to create an import for the view — and ‘index’ is not enough information to determine the import path.

    However, it’s far, far better to just name your views if you intend on reversing them, and you should also namespace your included urlpatterns so two different apps don’t end up conflicting. So in the project-level urls.py:

    urlpatterns = patterns('',
        url(r'^$', redirect_to, {'url': '/monitor/'}),
        url(r'^monitor/', include('monitor.urls', namespace='monitor', app_name='monitor')),
    )
    

    Then, in monitor/urls.py:

    urlpatterns = patterns('monitor.views',
        (r'^$', 'index', name='index'),
        (r'^list', 'listall', name='listall'),
    )
    

    Then, reversing is as simple as reverse('monitor:index').

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a couple problems understanding how redirect or rather reverse really work. In
I am still experiencing some problems with understanding forms and relationships between model-forms. I
I have been reading some django tutorial and it seems like all the view
I'm having problems understanding how I should install xhtml2pdf. I have followed the instructions
I am having some troubles understanding the object relationships in Django. I wrote this:
I'm having some trouble understanding many-to-many fields in Django. When I create a many-to-many
I'm having some trouble understanding import This piece of code works properly. I from
I am writing down my understanding of the CSRF protection mechanism in Django. Please
How should I implement reverse AJAX when building a chat application in Django? I've
I created some code to differentiate between two usergroups in Django admin, resulting in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.