Locally test different domain url configuration in Django

╄→гoц情女王★ 提交于 2019-12-11 17:05:11

问题


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]

Where the url_config[host] value points to app.urls in the settings MULTIURL_CONFIG dictionary. Each app is on a different domain.

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?


回答1:


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

for example:

# /etc/hosts
127.0.0.1     localhost mydomain pudipudi

then you can go to your browser to pudipudi:8000



来源:https://stackoverflow.com/questions/46748659/locally-test-different-domain-url-configuration-in-django

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