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

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

问题描述

我有一个奇怪的Django问题,运行Django与mod_wsgi。

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调试信息中所示,文件夹和其上的应用程序文件夹。如果我从命令行运行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\to\app\__init__.py

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

But in the wsgi version, I only see:

print app.__file__
>> \path\to\app\

换句话说,它只是找不到code> __ init __。pyc 。

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

推荐答案

可能是循环依赖 - 视图正在导入另一个模块,它本身正在尝试导入视图

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

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

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