4

我正在使用 django 并且有数百个子域 url

abc.domain.com 

想改写成

domain.com/site/abc/

是否有可能通过用户看不到的 url 重写

domain.com/site/abc/

在他的浏览器中,但看到

abc.domain.com 

这可以在 apache 端完成。但我的问题是,我们可以在 django 里面做吗?

提前致谢!

4

3 回答 3

0

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.

于 2013-02-03T03:32:18.643 回答
0

你有没有运行apache,我认为这种请求可以通过APACHE的重写引擎来处理

于 2014-10-24T04:23:27.960 回答
0

我不太明白你的问题,但也许一些摆弄 request.urlconf 和自定义中间件是解决方案? https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.urlconf

于 2013-02-02T23:28:37.400 回答