Django 错误:无法导入 csrf.py
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 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.
如果您(或您的系统管理员)最近更新了 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.