本文介绍了导入中间件app.middleware时导致错误:“无法导入名称get_host”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚升级到Django 1.5,当我尝试访问一个页面时,我收到以下错误:
I've just upgraded to Django 1.5, and when I try and access a page, I get the following error:
ImproperlyConfigured: Error importing middleware app.middleware: "cannot import name get_host"
在shell中,我尝试类似的事情:
In the shell, I try a similar thing:
>>> from app import middleware
Traceback (most recent call last):
File "<console>", line 1, in <module>
File ".../middleware.py", line 2, in <module>
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect, get_host
ImportError: cannot import name get_host
导入 get_host
失败。似乎这不被弃用,发生了什么?
It's failing on the import of get_host
. It doesn't seem that this is deprecated, what's going on?
推荐答案
在Django 1.5 django中。 http.get_host()
替换为 request.get_host()
。请参阅 HttpRequest
对象。
In Django 1.5 django.http.get_host()
is replaced with request.get_host()
. See the methods on HttpRequest
object here.
这篇关于导入中间件app.middleware时导致错误:“无法导入名称get_host”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!