I'm using django and have hundreds of subdomain url
abc.domain.com
want to rewrite to
domain.com/site/abc/
Is it possible via url-rewriting that the user won't see
domain.com/site/abc/
in his browser, but sees
abc.domain.com
This can be done at apache side. But my question is, can we do it inside django?
Thanks in advance!
I don't really understand you question, but maybe some fiddling with request.urlconf and custom middleware is the solution? https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.urlconf
The Django sites framework does provide some tools to deal with multiple domains, but they all assume you have a different SITE_ID for each deployment.
That said. You can probably write up a middleware that checks request.META['HTTP_HOST']
and then passes that information off to your view in whatever way you wish.
At that point you can just follow the Django docs on using a site custom manager for your models.
你有没有运行apache,我认为这种请求可以通过APACHE的重写引擎来处理
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.