问题
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