Can I create sub domain for each user in Django

只谈情不闲聊 提交于 2019-12-06 04:51:46

问题


I want users create their own account and users should get their own like user.foo.com and different point to different template folder. Is it possible in Django. I quite new to Django


回答1:


Django itself is unaware of whatever web server you are using. Usually, to configure extra sub-domains, you need to add virtual hosts to your webserver's configuration and make sure your DNS provider forwards requests for that sub-domain to the appropriate server.

To do this directly, you'll need to run Django under a user account that has write access to your webserver's configuration file, which is really not recommended. Assuming all the hosts are on the same machine, you could do this indirectly, such as queuing requests and have someone manually approve them and edit the file, or have a script run through cron and re-write the server configuration every X minutes/hours/days.

Also, DNS registration is a major issue. If you have a wildcard domain name such as "*.foo.com", you'll be fine. If your DNS provider doesn't allow this, you'll need to have someone register the extra sub-domains manually.

Basically, almost none this is related to Django, and almost all of it depends on your server's software stack (which you have not specified).




回答2:


The answer provided by Andre isn't exactly correct. You will indeed need a wildcard domain, most decent providers will allow this including GoDaddy (IE this is not a limitation you should be terribly concerned with).

"To do this directly, you'll need to run Django under a user account that has write access to your webserver's configuration file, which is really not recommended. Assuming all the hosts are on the same machine, you could do this indirectly, such as queuing requests and have someone manually approve them and edit the file, or have a script run through cron and re-write the server configuration every X minutes/hours/days."

This is completely wrong in basically every way. In fact all you need to pull this off is this:Subdomain Middleware. Simply couple that with an appropriate webserver config to accept requests to *.example.com and you have the necessary variable to take your queue off of in every view



来源:https://stackoverflow.com/questions/6543145/can-i-create-sub-domain-for-each-user-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!