8

我刚刚升级到 Django 1.5,当我尝试访问页面时,出现以下错误:

ImproperlyConfigured: Error importing middleware app.middleware: "cannot import name get_host"

在 shell 中,我尝试了类似的事情:

>>> 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。这似乎没有被弃用,这是怎么回事?

4

1 回答 1

10

在 Django 1.5django.http.get_host()中被替换为request.get_host(). 请参阅此处HttpRequest的对象方法。

于 2013-03-27T17:25:42.343 回答