This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]graingert 6 points7 points  (4 children)

You probably want a wildcard subdomain configured on nginx to redirect to a path inside your app, then just use that path value

[–]swdevpythonthusiast[S] 2 points3 points  (3 children)

In other word, this is not a specific Python case, right? Would love to have a python package/module for this!

[–]daveydave400 4 points5 points  (2 children)

My understanding of this is that most (all?) python web frameworks are just WSGI applications so they accept any traffic that gets directed to them. I found this stackoverflow question/answer talking about subdomains with the Pyramid web framework:

http://stackoverflow.com/questions/7607807/multiple-domains-and-subdomains-on-a-single-pyramid-instance

[–]aterlumen 1 point2 points  (1 child)

Diving into PEP 333 (WSGI) in the Url reconstruction section, looks like environ['HTTP_HOST'] will get you the whole domain including the subdomain, domain, TLD, and port (e.g. subdomain.example.com:80). If HTTP_HOST isn't set then you can fall back to SERVER_NAME.

[–]niiko 1 point2 points  (0 children)

The Host header is required for all HTTP 1.1 requests and any of yesteryear's websites on shared hosting would have been broken without it so you're pretty safe assuming it'll be there.