0

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 ?

Horai Nuri
  • 5,358
  • 16
  • 75
  • 127
  • What happens when you just try `web.site.ch`? With the subdomain stuff, you shouldn't have to put `/web` on the end of the URL. – themanatuf Mar 14 '17 at 15:19
  • @themanatuf same, I think I should since I'm modifying a page where you can only access with /web/ – Horai Nuri Mar 14 '17 at 16:20

1 Answers1

1

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.

Glenn
  • 7,262
  • 1
  • 17
  • 23
  • I see what would you recommend to achieve what I'm trying to do ? Django-hosts ? – Horai Nuri Mar 15 '17 at 20:33
  • Anything you do in Django is too late. You need the DNS and the web app and doing something in Django will do nothing to either of those. – Glenn Mar 16 '17 at 06:17
  • Do you have a tutorial to configure the web app ? I believe my DNS is already pointing to web.site.ch with the CNAME configuration – Horai Nuri Mar 16 '17 at 11:09
  • Each web app on PythonAnywhere corresponds to one domain; if you want to serve multiple domains, you need to add one for each domain (with a corresponding CNAME for each one). If you want them to run the same code, just make sure that they all have the same code in their WSGI file and the same other settings on the "Web" tab (eg. virtualenv, static file mappings, etc) – Giles Thomas Mar 23 '17 at 15:11