问题
I'm having an odd Django problem, running Django with mod_wsgi.
Django is finding urls.py
, and then saying:
ViewDoesNotExist: Could not import app.views. Error was: No module named views
Bizarrely, if I have
import app
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.
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.
I've tried printing the python path to stderr from urls.py
too, and it has the path to app in it.
What could be going on?
My first thought was that there might not be an __init__.py
in the app folder, but there is.
Thanks!
UPDATE
In the runserver app, if I try
print app.__file__
>> \path\to\app\__init__.py
But in the wsgi version, I only see:
print app.__file__
>> \path\to\app\
In other words, it's just not finding __init__.pyc
.
回答1:
Probably a circular dependency - something in views
is importing another module, which itself is trying to import views
.
回答2:
Your web server is out of file handles. Reconfigure the WSGI app for daemon mode.
来源:https://stackoverflow.com/questions/5119964/baffled-django-could-not-import-app-views-but-can-import-app-in-wsgi