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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:32:57+00:00 2026-05-19T04:32:57+00:00

I’ve been working with Django for a while now (currently on version 1.2), but

  • 0

I’ve been working with Django for a while now (currently on version 1.2), but just recently started working on an app that needs to support multiple instances. E.g., the project urls.py file will include it twice, under two different namespaces, like this:

urlpatterns = patterns('',
    (r'^instance1/', include('myapp.urls', namespace='instance1')),
    (r'^instance2/', include('myapp.urls', namespace='instance2')),
)

I was going along fine, until I realized I needed to figure out what to do about all the internal calls to reverse() (or the template calls to the {% url %} filter). For instance, let’s say I’m doing something like the following in one of my views:

return HttpResponseRedirect(reverse('view_name'))

or something like this in one of my templates:

<a href="{% url view_name %}">link text</a>

…where view_name is the name of a URL pattern contained in myapp.urls. Since I’m using namespaces, this will raise an error: there is no view called view_name. Rather, I have to tell it either instance1:view_name or instance2:view_name. But doing this dynamically is stumping me.

I did some looking and it looks like the current_app argument, passed to either Context or RequestContext, was designed to help with this, but it’s not clear at all how to dynamically pass the right application name to current_app. So what’s the right way to tell Django which namespace to use?

EDIT: My use case is to use a single installation of the app multiple times. That is, it only exists on disk once, but gets included multiple times in the project’s root urls.py (each time under a different namespace, as in my example above). With this in mind, is there any good way to keep track of which namespace a view/template is being called from, and make any use of reverse() or {% url %} stick within the same namespace? I know Django 1.3 will provide some extra features that could help with this (namely, the new and improved resolve()), but surely there’s a good way to do this now…

  • 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-05-19T04:32:57+00:00Added an answer on May 19, 2026 at 4:32 am

    Not a very nice solution, but since you use the same text for your namespace and initial part of the URL path, you can extract that element from request.path (request.path.split('/')[1]) and set that as current_app in the request context, or just use it as the namespace in views.

    http://docs.djangoproject.com/en/dev/topics/http/urls/#url-namespaces point 2.

    You could do that e.g. in a context processor (if you want to use the namespace in a template).

    For views you could write a decorator that feeds your function an extra kwarg “namespace” and use it as:

    @feed_namespace
    def view1(request, *args, **kwargs):
        ns = kwargs['namespace']
    

    or just write a reverse_namespaced function with an extra param (the request) where the function gets the namespace from, and use it instead of reverse.

    Of course if you do this you will always have to use a request path/namespace for this app

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

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.