简体   繁体   中英

django : ImportError No module named myapp.views.hometest

I have fecora 11, set django with mod_wsgi2.5 and apache2.2. And I can run "python manage.py runserver" at local. It works fine. I got error when i test from remote browser.

Thanks for any suggestion and help!

I just had this problem. It went away when I added sys.path.append('/path/to/project') to my .wsgi file.

Is the application containing your Django project in your $PYTHONPATH (when Python is invoked in a server context)? For example, if your Django project is at /home/wwwuser/web/myproj , then /home/wwwuser/web should be in your $PYTHONPATH . You should set this in the script that loads the project when invoked from the web server.

Just a guess, but unless you've explicitly made sure that your app is on PYTHONPATH, you should be specifying views in urls.py as myproject.myapp.views.functionname.

Otherwise:

  • check if you're setting PYTHONPATH, or what to. Your project directory should be in there.
  • if you enable the django admin (by uncommenting the lines that are there by default in urls.py), does that work?
  • All required env variables should be set in django.wsgi. You could compare the env declared in django.wsgi and the env of executing ./manage runserver and make sure they are same.
  • Furthermore, if there is another myapp package which could be found through PYTHONPATH before /usr/local/django/myapp , ImportError may be raised.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM