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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:19:55+00:00 2026-06-15T08:19:55+00:00

My question is about how to serve multiple urls.py (like urls1.py, urls2.py and so

  • 0

My question is about how to serve multiple urls.py (like urls1.py, urls2.py and so on) files in a single Django project.

I am using Win7 x64, django 1.4.1, python 2.7.3 and as a server django dev-server tool.
I have decided to use a method which i found by google from

http://effbot.org/zone/django-multihost.htm

I have created a multihost.py file and put in to the django middleware folder:

C:\python27\Lib\site-packages\django\middleware\multihost.py   

With the following code:

from django.conf import settings  
from django.utils.cache import patch_vary_headers  

class MultiHostMiddleware:  
def process_request(self, request):  

    try:  
        host = request.META["HTTP_HOST"]  
        if host[-3:] == ":80":  
            host = host[:-3] # ignore default port number, if present  
        request.urlconf = settings.HOST_MIDDLEWARE_URLCONF_MAP[host]  
    except KeyError:  
        pass # use default urlconf (settings.ROOT_URLCONF)  

def process_response(self, request, response):  
    if getattr(request, "urlconf", None):  
        patch_vary_headers(response, ('Host',))  
    return response  

Also in my project setting.py file i have added a mapping dictionary like the link above shows:

# File: settings.py 

HOST_MIDDLEWARE_URLCONF_MAP = { 

    "mysite1.com": "urls1", 
    #"mysite2.com": "urls2" 

    } 

I did not yet implemented the error handling like described by the link above.

My hosts file includes the follwoing:

127.0.0.1    mysite1.com  

Project structure is the following:

effbot django project folder:

 + effbot   
--- settings.py   
--- view.py   
--- wsgi.py   
--- urls.py   
--- urls1.py     

 + objex   
--- models.py   
--- views.py   

 + static   
--- css   
--- images   

There is no templates folder, because i dont serve html items from files, they are coming from databsse (i doubt that my problem is in this).

Now the problem is: when i go for the adress

mysite1.com   

in my browser with django dev-server launched i get code 301 from the server. And browser shows “cannot display page” message.

Could you please explain me how to use mentioned method? I’m new to django and haven’t done any real projects yet. Just have read the docs and launched a couple of sites at home to learn how it works.

I expect that urlconfs will be called in dependance from incoming

request.META["HTTP_HOST"]   

The target is to serve different urlconfs for mysite1.com and mysite2.com
in a single django project.

I think this should to work some how.

Thank you for any feedback.

EDIT:
After some research attempts i found that i plugged my multyhost.py incorrectly in settings.
Fixed now. But the same result still.

Also i found out that my django dev-server tool is not reflecting anyhow that it handles any requests from the browser (IE9) except when i do “http://127.0.0.1”.
May be i have to try some production server for my task, like nginx?

  • 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-15T08:19:57+00:00Added an answer on June 15, 2026 at 8:19 am

    Your ROOT_URLCONF should be effbot.urls without .pyas you can see in the example in the documentation.

    Also, HOST_MIDDLEWARE_URLCONF_MAP should reflect the ROOT_URLCONF so add `effbot. like this:

    HOST_MIDDLEWARE_URLCONF_MAP = { 
        "mysite1.com": "effbot.urls1", 
        #"mysite2.com": "effbot.urls2" 
    } 
    

    One more thing, please try with another browser (Chrome, Firefox), sometimes I had problems accessing dev server with IE.

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

Sidebar

Related Questions

I have a question about receiving emails. Using Ubuntu as the server, I have
The question is about Armenian. I'm using sql server 2005, collation SQL_Latin1_General_CP1_CI_AS, data mostly
I'm very new to Maven, and have a question about building multiple Maven projects.
To follow from my previous question about virtual and multiple inheritance (in a cross
Fundamentally, this question is about: Can the same DB connection be used across multiple
A previous question, Multiple directories and/or subdirectories in IPython Notebook session, asked about directory
I recently asked a question about writing to multiple tables: PHP/MySQL insert into multiple
Okay, so I've seen this question about this problem being caused by multiple linkings
My question is about deployment to a Tomcat server instance which hosts multiple applications
I have a question about SQL Server indexes. I'm not a DBA and assume

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.