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.

  1. 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.

  2. 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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

python - How to remove the Xframe Options header in django? -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -