我可以为 Django 中的每个用户创建子域吗 [英] Can I create sub domain for each user in Django

查看:18
本文介绍了我可以为 Django 中的每个用户创建子域吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用户创建自己的帐户,用户应该像 user.foo.com 一样拥有自己的帐户,并且指向不同的模板文件夹.在 Django 中可能吗?我对 Django 很陌生

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

推荐答案

Django 本身并不知道您正在使用什么 Web 服务器.通常,要配置额外的子域,您需要将虚拟主机添加到网络服务器的配置中,并确保您的 DNS 提供商将该子域的请求转发到适当的服务器.

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.

要直接执行此操作,您需要在对网络服务器配置文件具有写入权限的用户帐户下运行 Django,确实不建议这样做.假设所有主机都在同一台机器上,您可以间接执行此操作,例如排队请求并让某人手动批准它们并编辑文件,或者通过 cron 运行脚本并重新编写每 X 分钟/小时/天配置一次服务器.

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.

此外,DNS 注册也是一个主要问题.如果您有一个通配符域名,例如 "*.foo.com",那就没问题了.如果您的 DNS 提供商不允许这样做,您将需要有人手动注册额外的子域.

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.

基本上,几乎没有一个与 Django 相关,而且几乎所有这些都取决于您服务器的软件堆栈(您没有指定).

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

这篇关于我可以为 Django 中的每个用户创建子域吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆