Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><s>You have to do this at the webserver level (for example using mod_rewrite in Apache) or with middleware (for example <a href="http://www.djangosnippets.org/snippets/1119/" rel="nofollow noreferrer">this snippet</a>)</p> <p>Also see <a href="https://stackoverflow.com/questions/624827/in-a-django-web-application-how-do-you-give-users-their-own-subdomain">this SO question</a></s></p> <hr> <p>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:</p> <p><strong>Multiple sites:</strong> You need to use the <a href="http://docs.djangoproject.com/en/dev/ref/contrib/sites/" rel="nofollow noreferrer">Django sites framework</a>. Which means making site instances for each language using the Django admin.</p> <p><strong>Multiple settings:</strong> Each language site will also have its own settings.py. The only differences between each site will be the <code>SITE_ID</code> and <code>ROOT_URLCONF</code> settings so, to follow <a href="http://en.wikipedia.org/wiki/DRY" rel="nofollow noreferrer">DRY</a> principle, you should keep the common settings in a different file and import them into the master file like this:</p> <pre><code># 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 * </code></pre> <p>... and so on.</p> <p><strong>Multiple URL conf:</strong> As implied above, a url conf for each site:</p> <pre><code># 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"), ) </code></pre> <p>... and so on.</p> <p>This way the url name (in this example "books") is the same for all languages, and therefore <code>{% url books %}</code> will reverse properly and the domain name will be the domain_name field of the Site object with <code>SITE_ID</code>.</p> <p><strong>Multiple web server instances:</strong> 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:</p> <pre><code># site_fr.wsgi import os, sys, django.core.handlers.wsgi os.environ['DJANGO_SETTINGS_MODULE'] = 'app.settings_fr' application = django.core.handlers.wsgi.WSGIHandler() </code></pre> <p>... and so on along with matching apache virtual host for each site:</p> <pre><code>&lt;VirtualHost *:80&gt; ServerName mybooks.fr WSGIScriptAlias / /path/to/site_fr.wsgi ... &lt;/VirtualHost&gt; </code></pre> <p>Hopefully this is clear :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload