困惑:Django“无法导入 app.views"但是可以在 WSGI 中导入应用程序吗? [英] Baffled: Django "could not import app.views" but can import app, in WSGI?

查看:42
本文介绍了困惑:Django“无法导入 app.views"但是可以在 WSGI 中导入应用程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 mod_wsgi 运行 Django 时遇到了一个奇怪的 Django 问题.

I'm having an odd Django problem, running Django with mod_wsgi.

Django 正在查找 urls.py,然后说:

Django is finding urls.py, and then saying:

ViewDoesNotExist: Could not import app.views. Error was: No module named views

奇怪的是,如果我有

import app

urls.py 的导入语句中,我没有收到错误(直到它像上面一样命中 app.views),但如果我有

in the import statements in urls.py I don't get an error (until it hits app.views as above), but if I have

from app import views

在我的导入语句中,我收到一个错误.

in my import statements, I get an error.

我的 python 路径,如 Django 调试信息中所示,包含文件夹和 app 文件夹.如果我从命令行运行 Python,我可以很好地导入 app.views.我可以使用 python manage.py runserver 运行应用程序就好了.

My python path, as shown in the Django debug info, has both the containing folder and the app folder on it. If I run Python from the command line, I can import app.views just fine. I can run the app using python manage.py runserver just fine.

我也试过从 urls.py 打印到 stderr 的 python 路径,它有应用程序的路径.

I've tried printing the python path to stderr from urls.py too, and it has the path to app in it.

会发生什么?

我的第一个想法是应用文件夹中可能没有 __init__.py,但有.

My first thought was that there might not be an __init__.py in the app folder, but there is.

谢谢!

更新

在 runserver 应用程序中,如果我尝试

In the runserver app, if I try

print app.__file__
>> path	oapp\__init__.py

但是在wsgi版本中,我只看到:

But in the wsgi version, I only see:

print app.__file__
>> path	oapp

换句话说,就是找不到__init__.pyc.

In other words, it's just not finding __init__.pyc.

推荐答案

可能是循环依赖 - views 中的某些内容正在导入另一个模块,该模块本身正在尝试导入 views.

Probably a circular dependency - something in views is importing another module, which itself is trying to import views.

这篇关于困惑:Django“无法导入 app.views"但是可以在 WSGI 中导入应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆