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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:29:30+00:00 2026-06-12T04:29:30+00:00

I have been trying to to figure out how to define a nested URL

  • 0

I have been trying to to figure out how to define a nested URL namespace (which look:like:this) in a Django URLConf.

Before this, I figured out how to do a basic URL namespace and came up with this simple example snippet, containing what you might put in a urls.py file:

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

# you can only define a namespace for urls when calling include():

app_patterns = patterns('',
    url(r'^(?P<pk>[\w\-]+)/$', 'yourapp.views.your_view_function',
        name="your-view"),
)

urlpatterns = patterns('',
    url(r'^view-function/', include(app_patterns,
        namespace='yournamespace', app_name='yourapp')),
)

"""

    You can now use the namespace when you refer to the view, e.g. a call
    to `reverse()`:

    # yourapp/models.py

    from django.core.urlresolvers import reverse

    # ...

    class MyModel(models.Model):

        def get_absolute_url(self):
            return reverse('signalqueue:exception-log-entry', kwargs=dict(pk=self.pk))

"""

… w/r/t the deduction of which the Django documentation was, in this case, not at all helpful. While Django’s doc is fantastic in all other respects, and this is an exception to the rule, there is even less information about defining nested URL namespaces.

Instead of posting my spaghettified attempts† to figure this out, I thought I might ask if anyone has, or knows of, a straightforwardly cogent and/or self-explanatory example of a URLconf that defines a nested namespace, that they could share.

Specifically I am curious about the nested parts that prefix the view: need they all be installed Django apps?

†) For the curious, here’s a (probably somewhat inscrutable) example: https://i.stack.imgur.com/53gNL.jpg. I was trying to get the URLs printed out in red and green at the bottom to be named testapp:views:<viewname> instead of just testapp:<viewname>.

  • 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-12T04:29:31+00:00Added an answer on June 12, 2026 at 4:29 am

    It works rather intuitively. include a urlconf that has yet another namespaced include will result in nested namespaces.

    ## urls.py
    nested2 = patterns('',
       url(r'^index/$', 'index', name='index'),
    )
    
    nested1 = patterns('',
       url(r'^nested2/', include(nested2, namespace="nested2"),
       url(r'^index/$', 'index', name='index'),
    )   
    
    urlpatterns = patterns('',
       (r'^nested1/', include(nested1, namespace="nested1"),
    )
    
    reverse('nested1:nested2:index') # should output /nested1/nested2/index/
    reverse('nested1:index') # should output /nested1/index/
    

    It’s a great way to keep urls organized. I suppose the best advice I can give is to remember that include can take a patterns object directly (as in my example) which lets you use a single urls.py and split views into useful namespaces without having to create multiple urls files.

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

Sidebar

Related Questions

I have been trying to figure out why I am getting this problem and
I have been trying to figure out how to read paragraph content which exists
I have been trying to figure this out for quite a while, but what
I have been trying to figure this out for way to long tonight. I
Okay I've been trying to figure this out for a while now. I have
I have been trying to figure this out all afternoon with no luck. On
I have been trying to figure this out for a while now and even
I've been trying to figure out this problem. I have an assignment to make
I have been trying to figure out how to open a file from the
I have been trying to figure out a solution but nothing has really presented

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.