Django ImportError:无法导入设置“settings” - 没有名为 csrf 的模块

发布于 2024-10-06 07:25:10 字数 1732 浏览 6 评论 0原文

我刚刚开始摆弄 django。首先我在我的 Windows 机器上制作了一个小应用程序并验证它工作正常 然后,我压缩了整个项目,并在 Linux 机器上打开了 zip。 当然,Linux 机器安装了 mod_wsgi 和 django 1.1.1。

我创建了以下目录:

  • /usr/local/bin/ROOT - 仅包含一个文件 django.wsgi
  • /usr/local/bin/ROOT/myapp - django 应用程序的根目录

按照此处的说明,我添加了到 httpd.conf

<VirtualHost *:80>

    ServerName server
    ServerAlias server
    ServerAdmin [email protected]


    WSGIScriptAlias /myapp /usr/local/bin/ROOT/django.wsgi

    <Directory /usr/local/bin/ROOT/>
    Order allow,deny
    Allow from all
    </Directory>

</VirtualHost>

现在按照这里的说明< /a> 我放入 /usr/local/bin/ROOT/django.wsgi:

import os
import sys
path = '/usr/local/bin/ROOT'
if path not in sys.path:
    sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

如果它有任何重要性的话:在应用程序启动之前,PYTHOHPATH 上没有设置任何内容。

之后我优雅地重新启动了 apache,然后转到 server/myapp。我收到了 500 错误。 查看日志我看到:

[Sun Dec 05 12:24:17 2010] [error] [client XXXX] ImproperlyConfigured: Error importing middleware django.middleware.csrf: "No module named csrf"

我做错了什么?我发现的有关此问题的所有其他线程总是要么得出结论,即它是旧版本的 django(但我的是 1.1.1),要么有多个应用程序正在运行,但我只有一个......

帮助?

I am just starting to fiddle around with django. First I made a small app on my windows machine and verified it worked fine
Then, I zipped the entire project, and opened the zip on a linux machine.
The linux machine was installed with mod_wsgi and django 1.1.1, of course.

I created the following dirs:

  • /usr/local/bin/ROOT - contains only one file, django.wsgi
  • /usr/local/bin/ROOT/myapp - root dir of django app

Per the instructions here, I added to httpd.conf:

<VirtualHost *:80>

    ServerName server
    ServerAlias server
    ServerAdmin [email protected]


    WSGIScriptAlias /myapp /usr/local/bin/ROOT/django.wsgi

    <Directory /usr/local/bin/ROOT/>
    Order allow,deny
    Allow from all
    </Directory>

</VirtualHost>

Now per the instructions here I put in /usr/local/bin/ROOT/django.wsgi:

import os
import sys
path = '/usr/local/bin/ROOT'
if path not in sys.path:
    sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

If it is of any importance: there is nothing set on PYTHOHPATH before the application starts.

After that I did a graceful restart to apache, and went to server/myapp. I got a 500 error.
Lookin in the log I see:

[Sun Dec 05 12:24:17 2010] [error] [client XXXX] ImproperlyConfigured: Error importing middleware django.middleware.csrf: "No module named csrf"

What am I doing wrong? all other threads I found about this always either end up with a conclusion that it's an old version of django (but mine's 1.1.1) or that there are several apps running, but I have only one...

Help?

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

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

发布评论

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

评论(2

定格我的天空 2024-10-13 07:25:10

“django.middleware.csrf”是 Django 1.2.x 中的包

对于 Django 1.1.x CSRF 设置,请阅读相应的文档 这里

1.1.x 中的包是“django.contrib.csrf.middleware.CsrfMiddleware”

"django.middleware.csrf" is the package in Django 1.2.x

For Django 1.1.x CSRF settings read the appropriate docs Here

The package in 1.1.x was "django.contrib.csrf.middleware.CsrfMiddleware"

南冥有猫 2024-10-13 07:25:10

1.1.1 Django 的旧版本(当前版本是1.2.3),这几乎肯定是问题的原因。 1.1.1 中没有 django.middleware.csrf。

1.1.1 is an old version of Django (the current version is 1.2.3), and that's almost certainly the cause of your problem. There is no django.middleware.csrf in 1.1.1.

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