Forums

Django site live at username.pythonanywhere.com, but only from some computers

Hi, my Django site at http://username.pythonanywhere.com/ is live, but only accessible from username.pythonanywhere.com If I try accessing it in browser by typing in www.username.pythonanywhere.com I see the default PA message:

Coming Soon! This is going to be another great website hosted by PythonAnywhere page.

I have a basic paid $5 package and my settings.py files has these allowed hosts:

ALLOWED_HOSTS = [
    'username.pythonanywhere.com',
    '.pythonanywhere.com',
    '.googleapis.com',
]

Should it be something like

ALLOWED_HOSTS = [
    'username.pythonanywhere.com',
    'www.username.pythonanywhere.com',
    '.pythonanywhere.com',
    '.googleapis.com',
]

Can someone give me a hand please? I'm new at this. Cheers, Jurgen

Hi Jurgen,

A slightly long answer for you, but I figured it was best to explain things properly rather than just give you the tl;dr version :-) But in case you just want the short version -- we only support web apps on your own custom domains and on yourusername.pythonanywhere.com. www.yourusername.pythonanywhere.com is not supported.

OK, here's the details:

The ALLOWED_HOSTS Django setting just tells it that it's OK if it receives requests for those sites. The only thing you should have in there for a site at jurgenizer.pythonanywhere.com is jurgenizer.pythonanywhere.com. The only way in which it's connected to the host names that are used to access your site is that those host names must appear in it. So, if X is a hostname for your site, it must appear in there, but X being in there doesn't make it a hostname for your site.

Routing requests to your web app is done by a combination of DNS and the web apps you have set up on the "Web" tab. If you had a domain www.something.com registered with a domain name registrar, you'd set up a web app on the "Web" tab called "www.something.com". This would give you an identifier of a part of PythonAnywhere (something like webapp-1234.pythonanywhere.com), and you'd then go to your registrar and set up some DNS settings to say that www.something.com has a "CNAME" pointing that address to webapp-1234.pythonanywhere.com. So requests to www.something.com would go to the appropriate part of PythonAnywhere, which would recognise them as belonging to a particular web app, and process them using the code for that web app.

Of course, in this case, you don't own the pythonanywhere.com domain, so all of the DNS stuff has already been done by us. Basically we've set it up so that yourusername`.pythonanywhere.com always goes to the appropriate part of PythonAnywhere for that user's web apps.

But we haven't done the equivalent DNS setup for www.yourusername.pythonanywhere.com.

Does that make things a bit clearer?

That is excellent answer, I have a much better understanding of how it works - thank you for the fast response too!

No problem, glad to help!

Excuse me for my question) but this means that I need to specify allowed hosts www.mydomain.com? not a cname?

You need to specify the address that you web app is served from i.e. the name at the top of the web app configuration page.

Thank you so much, bro! The problem as always was that the domain was not yet registered

I am tired of this error

DisallowedHost at / Invalid HTTP_HOST header: 'subrahmanyam0326.pythonanywhere.com'. You may need to add 'subrahmanyam0326.pythonanywhere.com' to ALLOWED_HOSTS.

settings.py:

ALLOWED_HOSTS=['subrahmanyam0326.pythonanywhere.com']

Can we take a look at your code? We can see it from our admin interface, but we always ask for permission first.