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

  • SEARCH
  • Home
  • 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 8038853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:22:29+00:00 2026-06-05T03:22:29+00:00

I was having some problems with the regex in urls.py (I am a beginner

  • 0

I was having some problems with the regex in urls.py (I am a beginner to django as well as regexes in general)

Here is my original urls.py

url(r'^name/(?P<name>\w+)/$', 'course.views.name'),
url(r'^', 'course.views.index'),

And I was trying to access it using this:

http://127.0.0.1:8000/name/blah/

My view looks like:

def index(request):
    return HttpResponse("Hello, sam. You're at the course index.")

def name(request, name):
    return HttpResponse("Hello, %s. You're at the course index." % name)

The result I was getting was that for no matter what input I gave, I would regularly get the “index” function, and not the “name” function. I thought the problem was with the first regex.

But then, I changed the the 2nd one to:

url(r'^$', 'course.views.index'),

And THIS works just the way I figured it to work!

I understand that “$” means end of line, but shouldnt the 1st regex have been evaluated first? What is the order in which these expressions are matched?

Adding a “$” to every url is not that big a deal, but I would like to understand why I am putting it there.

I am using Django1.4 and Python 2.7

  • 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-05T03:22:30+00:00Added an answer on June 5, 2026 at 3:22 am

    Read the Django document

    How Django processes a request

    When a user requests a page from your
    Django-powered site, this is the algorithm the system follows to
    determine which Python code to execute:

    1. Django determines the root URLconf module to use. Ordinarily, this is the value of the ROOT_URLCONF setting, but if the incoming
      HttpRequest object has an attribute called urlconf (set by middleware
      request processing), its value will be used in place of the
      ROOT_URLCONF setting.
    2. Django loads that Python module and looks for the variable urlpatterns. This should be a Python list, in the format returned by
      the function django.conf.urls.patterns().
    3. Django runs through each URL pattern, in order, and stops at the first one that matches the requested URL.
    4. Once one of the regexes matches, Django imports and calls the given view, which is a simple Python function. The view gets passed an
      HttpRequest as its first argument and any values captured in the regex
      as remaining arguments.
    5. If no regex matches, or if an exception is raised during any point in this process, Django invokes an appropriate error-handling view.
      See Error handling below.

    It said 3. Django runs through each URL pattern, in order, and stops at the first one that matches the requested URL. So I think this is a bug.

    You should add $ in every url pattern unless Including other URLconfs

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

Sidebar

Related Questions

am having problems with some Regex code can anyone help. I have the following
Having some problems figuring out the regex to match this: function Array() { [native
Having some problems with a piece of Jquery code, well that's where I think
Im having some problems with redirections. Im using primefaces and JSF 2.1. The thing
I having some problems overloading the Index action in a controller. In the controller
Im having some problems with .on() and how to use it instead of .bind()
Currently having some problems- now = datetime.datetime.now() month = now.strftime(%B) site = wikipedia.getSite('en', 'wikiquote')
Im having some problems getting the Sticky Footer to work on my site. If
Im having some problems with a simple toggle in Safari. A really annoying flickering
i'm having some problems with C++ and nested classes. For example: in main.cpp int

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.