Django 错误:无法导入 csrf.py

发布于 2024-08-13 18:20:26 字数 1636 浏览 2 评论 0原文

我的 Django 应用程序突然开始崩溃,我不明白为什么。我现在甚至无法让它运行。我正在运行修订版 11798。

当我使用独立服务器测试我的应用程序时,它突然开始不导入 csrf。我以前让它工作得很好。我尝试使用 shell 来查看发生了什么,结果如下:

$ ./manage.py shell
Python 2.6.3 (r263:75184, Oct  2 2009, 07:56:03) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
>>> import django
>>> from django import middleware
>>> from django.middleware import csrf
Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: cannot import name csrf
>>>

我检查了文件系统以查看文件是否存在并且它是(并且完好无损)。我非常困惑。有人可以帮我吗?

Django 错误如下:

File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/core/servers/basehttp.py", line 279, in run
    self.result = application(self.environ, self.start_response)

  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/core/servers/basehttp.py", line 651, in __call__
    return self.application(environ, start_response)

  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/core/handlers/wsgi.py", line 230, in __call__
    self.load_middleware()

  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/core/handlers/base.py", line 42, in load_middleware
    raise exceptions.ImproperlyConfigured, 'Error importing middleware %s: "%s"' % (mw_module, e)

ImproperlyConfigured: Error importing middleware django.middleware.csrf: "No module named csrf"

My Django app started breaking all of a sudden and I cannot understand why. I can't even get it to run now. I'm running revision 11798.

When I use the stand-alone server to test my app, it suddenly started not importing csrf. I previously had it working perfectly. I tried to see what was up by using the shell and here was the result:

$ ./manage.py shell
Python 2.6.3 (r263:75184, Oct  2 2009, 07:56:03) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
>>> import django
>>> from django import middleware
>>> from django.middleware import csrf
Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: cannot import name csrf
>>>

I checked the filesystem to see if the file was there and it was (and intact). I am horribly confused. Can anyone help me out?

The Django error follows:

File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/core/servers/basehttp.py", line 279, in run
    self.result = application(self.environ, self.start_response)

  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/core/servers/basehttp.py", line 651, in __call__
    return self.application(environ, start_response)

  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/core/handlers/wsgi.py", line 230, in __call__
    self.load_middleware()

  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/core/handlers/base.py", line 42, in load_middleware
    raise exceptions.ImproperlyConfigured, 'Error importing middleware %s: "%s"' % (mw_module, e)

ImproperlyConfigured: Error importing middleware django.middleware.csrf: "No module named csrf"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

圈圈圆圆圈圈 2024-08-20 18:20:26

您的 python 路径中是否有多个 Django 副本?确保您没有任何旧的安装。

Do you have more than one copy of Django in your python path? Make sure you don't have any old installs laying around.

漫漫岁月 2024-08-20 18:20:26

如果您(或您的系统管理员)最近更新了 Django 安装,您可能对此感兴趣 CSRF 更改 - 向后不兼容,日期为 10/27/2009。

If you (or your sysadmin) recently updated your Django install, you may be interested in this CSRF changes - backwards incompatible, dated 10/27/2009.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文