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 8370719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:58:51+00:00 2026-06-09T13:58:51+00:00

I have a couple problems understanding how redirect or rather reverse really work. In

  • 0

I have a couple problems understanding how redirect or rather reverse really work.

In the main urls.py I have:

from django.conf.urls import patterns, include, url
from django.views.generic.simple import redirect_to

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

and in monitors.urls I have:

from django.conf.urls import patterns, include, url 

urlpatterns = patterns('monitor.views',
        (r'^$', 'index'),
        (r'^abc/(?P<id>.*$)', 'abc'),
)   

When you call /monitor I want to redirect it to /monitor/abc so I did:

def index(request):
    return redirect("abc")

def abc(render, id=None):
    return render_to_response("monitor/list.htmld", {})

But I got an NoReverseMatch exception. But when I do:

def index(request):
    return redirect("abc/")

then it suddenly works.

I cannot fully understand why. Why did reverse fail with abc but not with abc/? And how does reverse know that the redirect should include monitor/ as well? What if I had in the main urls.py another app called xyz which also has a abc view?

  • 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-09T13:58:53+00:00Added an answer on June 9, 2026 at 1:58 pm

    Why did reverse fail with ‘abc’ but not with ‘abc/’?

    Because it interpreted it as a view name (and you indeed have a view named 'abc', see your monitor.urls file). This means Django will call reverse to compute the URL. The value abc/ is interpreted as an actual URL which means Django won’t call reverse to determine the URL.

    This also explains why reverse failed: the view with name abc also requires an argument called id. Otherwise Django won’t be able to lookup the URL as there is no view called abc without parameters.

    Based on the documentation you should be able to reverse the URL using:

    redirect("abc", id=...)
    

    where ... is the value of the id parameter.

    And how does reverse know that the redirect should include monitor/ as well?

    That is because it knows what URLs are available and 1) it knows where the view called abc is defined and 2) it knows that monitors.urls is included with monitor/ in front.

    What if I had in the main urls.py another app called “xyz” which also has a “abc” view?

    In that case you have to use namespaces.

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

Sidebar

Related Questions

I have a couple of problems. I'm creating a form inside a table, from
I have a couple other pages on the website that have no problems with
We have a couple of sites which have some memory problems and fairly often
Here's the problem: I have couple of pages which gets its content from a
I have couple of formulas and data coming from database. I want to refresh
I have a couple of problems when doing blending in WebGL. One of them
I had a look at cx_Oracle but I have a couple of problems with
I'm fairly new to WCF development and have run into a couple problems whilst
I've just started using LINQ and I'm having a couple of problems understanding how
I have a couple of problems with my container DIV. For one it is

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.