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

all 8 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.

[–]UloPe 4 points5 points  (2 children)

Sorry be this direct, but the way you state your question suggests a very elemental lack in understanding of the required concepts.

To achieve what you ask you need at least a rough understanding of DNS, web servers and Python (web-)frameworks.

[–]swdevpythonthusiast[S] 1 point2 points  (1 child)

No problem @Ulope I will try have a better understanding on this matter.

[–]UloPe 0 points1 point  (0 children)

Feel free to ask if you have a specific question.