[Django]-Django : ImportError No module named myapp.views.hometest

4👍

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

👤Joshua

2👍

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.

👤mipadi

1👍

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?

1👍

  • 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.
👤okm

Leave a comment