如何 运行 不同子域上的不同 Django 应用程序
How to run different Django apps on different subdomain
是否可以 运行 不同子域上的不同 Django 应用程序。
例如:
对于 api.mydomain.com
,所有请求都将由我的 API
应用处理。但所有其他请求将由我的 core app
处理。
我只想让我的 API
应用程序处理在 api.mydomain.com
上提出的请求。所有其他 requests
应该简单地传递给 www.mydomain.com
.
不完全是您问题的答案,但如果您希望根据请求在同一 URI 中为您的网站提供 API,Django Rest Framework is recommended for doing it. With DRF you can can serve both regular webpages (TemplateHTMLRenderer) and API responses (JSONRenderer)。
如果您确实需要将 API 放在不同的子域中,那么 het.oosten 的建议对您有用。
希望对您有所帮助。
我用过django-subdomains
.
Subdomain helpers for the Django framework, including subdomain-based URL routing and reversing.
在 http://django-subdomains.readthedocs.org/en/latest/index.html
处找到解决方案
是否可以 运行 不同子域上的不同 Django 应用程序。 例如:
对于 api.mydomain.com
,所有请求都将由我的 API
应用处理。但所有其他请求将由我的 core app
处理。
我只想让我的 API
应用程序处理在 api.mydomain.com
上提出的请求。所有其他 requests
应该简单地传递给 www.mydomain.com
.
不完全是您问题的答案,但如果您希望根据请求在同一 URI 中为您的网站提供 API,Django Rest Framework is recommended for doing it. With DRF you can can serve both regular webpages (TemplateHTMLRenderer) and API responses (JSONRenderer)。
如果您确实需要将 API 放在不同的子域中,那么 het.oosten 的建议对您有用。
希望对您有所帮助。
我用过django-subdomains
.
Subdomain helpers for the Django framework, including subdomain-based URL routing and reversing.
在 http://django-subdomains.readthedocs.org/en/latest/index.html
处找到解决方案