在Django中本地测试不同的域url配置 [英] Locally test different domain url configuration in Django
问题描述
正如标题所述,我该如何测试不同的域不子域url路由?
As the title says how do i test different domain not subdomain url routing?
我正在使用如下中间件:
I'm using a middleware as follows:
class MultipleDomainMiddleware(MiddlewareMixin):
def process_request(self, request):
url_config = getattr(settings, 'MULTIURL_CONFIG', None)
if url_config is not None:
host = request.get_host()
if host in url_config:
request.urlconf = url_config[host]
其中 url_config [host]
值指向设置 MULTIURL_CONFIG
词典中的 app.urls
.每个应用程序都在不同的域中.
Where the url_config[host]
value points to app.urls
in the settings MULTIURL_CONFIG
dictionary. Each app is on a different domain.
现在,在本地测试时,我位于localhost:8000/上,那么如何进行测试,以便可以在本地测试跨域的路由模式以及共享数据?
Now, when locally testing I'm on localhost:8000/ so how can I test this so I can test my routing schema as well as shared data across the domains locally?
推荐答案
如果我没有误解您的问题,并且您使用的是Linux,则可以将localhost所需的所有域添加到/etc/hosts文件中测试
if i didn't misunderstood your question and you're using linux, you could add to /etc/hosts file next to localhost all the domains that you want to test
例如:
# /etc/hosts
127.0.0.1 localhost mydomain pudipudi
然后您可以进入浏览器以 pudipudi:8000
then you can go to your browser to pudipudi:8000
这篇关于在Django中本地测试不同的域url配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!