python - Using subdomains in django -
please tell me whether possible (if so, how) use pages each user subdomains. example, have url of form: http://hostname.com/user/1 need http://username.hostname.com/
you have number of options depending on how in-depth want go.
one option handle routing @ web server level. capture subdomain part of url , rewrite different location within server.
for example
http://username1.local.host/signin
captured webserver , internally routed resource such/username1/signin
. end user subdomains code handle url parts none wiser has happened.your urls.py handle normal request.
url_pattern = [ ... url(r'(?p<subdomain>[a-z]+)/sigin/$', 'view'), ]
for nginx need "subdomain subdirectory re-writing".
i use option have stated in question. whilst method little more tricky setup (keep @ until works). lot easier maintain , work in long run. use option have stated in question.
the other option handle subdomains @ django level using package such django subdomains (i have used 1 in past , found preferred option (in terms of handling subdomains within django code)). without going detail nginx capture subdomains , route of django. django handle subdomains @ middleware level.
personally use option 1 usage. option 2 if want different apps on different domains example: blog.local.host
, support.local.host
.
Comments
Post a Comment