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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:50:08+00:00 2026-05-11T11:50:08+00:00

How do I set urlpatterns based on domain name or TLD, in Django? For

  • 0

How do I set urlpatterns based on domain name or TLD, in Django?

For some links, Amazon shows url in native language based on its website tld.

http://www.amazon.de/bücher-buch-literatur/ ( de : books => bücher )

http://www.amazon.fr/Nouveautés-paraître-Livres/ ( fr : books => Livres )

http://www.amazon.co.jp/和書-ユーズドブッ-英語学習/ ( jp : books => 和書 )

( the links are incomplete and just show as samples. )

Is it possible to get host name in urls.py? (request object is not available in urls.py) or maybe in process_request of middleware and use it in urls.py(how???)

Any alternate suggestions how to achive this?

#---------- pseudocode ----------   website_tld = get_host(request).split('.')[-1]  #.fr French  : Books : Livres #.de German : Books : Bücher  if website_tld == 'fr':     lang_word = 'Livres' elif website_tld == 'de':     lang_word = 'Bücher' else:     lang_word = 'books'  urlpatterns = patterns('',                        url(r'^%s/$' % lang_word,books_view, name='books'),                        ) 

The url pattern needs to be built based on tld and later in the template, <a href='{% url books %}' >{% trans 'books' %}</a> to render html as <a href='Bücher'>Bücher</a> or <a href='Livres'>Livres</a>

  • 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. 2026-05-11T11:50:08+00:00Added an answer on May 11, 2026 at 11:50 am

    You have to do this at the webserver level (for example using mod_rewrite in Apache) or with middleware (for example this snippet)

    Also see this SO question


    Update: after your comment I thought about it some more. I liked Carl Meyer’s answer, but then realized it wouldn’t handle {% url %} reversing properly. So here’s what I would do:

    Multiple sites: You need to use the Django sites framework. Which means making site instances for each language using the Django admin.

    Multiple settings: Each language site will also have its own settings.py. The only differences between each site will be the SITE_ID and ROOT_URLCONF settings so, to follow DRY principle, you should keep the common settings in a different file and import them into the master file like this:

    # settings_fr.py SITE_ID = 1 ROOT_URLCONF = 'app.urls_fr' from settings_common import *  # settings_de.py SITE_ID = 2 ROOT_URLCONF = 'app.urls_de' from settings_common import * 

    … and so on.

    Multiple URL conf: As implied above, a url conf for each site:

    # urls_fr.py urlpatterns = patterns('',     url(r'^Livres/$', books_view, name='books'), )  # urls_de.py urlpatterns = patterns('',     url(r'^Bücher/$', books_view, name='books'), ) 

    … and so on.

    This way the url name (in this example ‘books’) is the same for all languages, and therefore {% url books %} will reverse properly and the domain name will be the domain_name field of the Site object with SITE_ID.

    Multiple web server instances: In order for each SITE to work properly they each need their own server instances. For apache + mod_wsgi this means a different wsgi application for each SITE like this:

    # site_fr.wsgi import os, sys, django.core.handlers.wsgi os.environ['DJANGO_SETTINGS_MODULE'] = 'app.settings_fr' application = django.core.handlers.wsgi.WSGIHandler() 

    … and so on along with matching apache virtual host for each site:

    <VirtualHost *:80>     ServerName mybooks.fr     WSGIScriptAlias / /path/to/site_fr.wsgi     ... </VirtualHost> 

    Hopefully this is clear 🙂

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

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Specific concepts like, Endianness (this link is to an old… May 11, 2026 at 11:40 pm
  • Editorial Team
    Editorial Team added an answer You should be able to get the raw bitmap data… May 11, 2026 at 11:40 pm
  • Editorial Team
    Editorial Team added an answer You mean to see if the string is in the… May 11, 2026 at 11:40 pm

Related Questions

How do I set the symbol for the angle or annuity operation in LaTeX?
How do I set an attribute on a field anywhere in my assembly, then
How do I set the initial width of a QDockWidget? I have implemented the
How do I set the background colour of a listbox? I have a listbox

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.