Django's HttpResponseRedirect seems to strip off my subdomain?

自作多情 提交于 2019-11-29 02:46:37
SmileyChris

Django has some methods it always applies to a response. One of these is django.http.utils.fix_location_header. This ensures that a redirection response always contains an absolute URI (as required by HTTP spec).

This method uses request.build_absolute_uri, which in-turn uses request.get_host. get_host tries to get the HTTP_HOST from request.META, falling back to using SERVER_NAME.

My guess is that your server isn't providing the HTTP_HOST and that your SERVER_NAME is set to mydomain.com.

Hopefully now you know what you're looking for, you can run some tests to see what's going wrong.

The HttpResponseRedirect will simply return a 302 status code with the Location header set. The url resolver won't take the subdomain into consideration ( see http://code.djangoproject.com/ticket/8896 ). Your best bet it to either reconstruct it from scratch (HTTP_HOST on META) or just use the Middleware from http://thingsilearned.com/2009/01/05/using-subdomains-in-django/ .

Cheers

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