Horai Nuri
Horai Nuri

Reputation: 5578

How to set subdomains with django?

I've deployed my site on pythonanywhere.com, now I'd like to configure subdomains on some pages and I was wondering what I'm doing wrong using django-subdomains package ?

Here is what my code looks like :

settings.py :

... (already installed 'subdomains' in INSTALLED_APPS)

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'subdomains.middleware.SubdomainURLRoutingMiddleware', #before CommonMiddleware
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'site.urls'

SUBDOMAIN_URLCONFS = {
    None: 'site.urls',
    'www': 'site.urls',
    'web': 'pages.urls.web',
    'account': 'site.urls.login',
}

SITE_ID = 1
...

site/urls :

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^accounts/login/$', auth_views.login, name='login'),
    url(r'^', include('pages.urls')),
    url(r'^accounts/', include('utilisateur.urls')),
] ...

pages/urls :

urlpatterns = [
    ...
    url(r'^$', views.index, name="index"),
    url(r'^web/$', views.web, name="web"),
    ...
]

When I type web.site.ch/web/, the adress is not found. www.site.ch/web/ still exist while it should be web.site.ch/web/, same for accounts.site.ch/..., why it isn't ? Should I set up a DNS to my pythonanywhere server ?

Upvotes: 0

Views: 2618

Answers (1)

Glenn
Glenn

Reputation: 5786

To get a web request to make it to a web app, you need 2 things:

  1. A DNS entry for the address
  2. A web app on PythonAnywhere named to match the DNS entry

django-subdomains does not do either of those.

Upvotes: 0

Related Questions