English 中文(简体)
Django Error: Cannot Import csrf.py
原标题:
  • 时间:2009-12-09 00:56:50
  •  标签:
  • django
  • 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"
最佳回答

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

问题回答

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





相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签