Forums

WSGI Unable to find Django

Hi,

I'm having trouble pointing my wsgi to Django with errors. I've created the virtualenv manually, installed django manually via pip, cloned the files I require for the website via github and proceeded to the Web tab to let the wsgi point to Django etc. To see if it is working, I tried to hit migrate on Bash. I get a couple of errors saying Django.urls include not found.

wsgi.py

> # +++++++++++ DJANGO +++++++++++
> # To use your own Django app use code like this: import os import sys
> 
> path =
> '/home/rickson/.virtualenvs/ypfvirtualenv/python-project/mysite' if
> path not in sys.path:
>     sys.path.append(path)
> 
> 
> os.environ("DJANGO_SETTINGS_MODULE", "mysite.settings")
> 
> ## Uncomment the lines below depending on your Django version
> ###### then, for Django >=1.5: from django.core.wsgi import get_wsgi_application application = get_wsgi_application()
> ###### or, for older Django <=1.4
> #import django.core.handlers.wsgi
> #application = django.core.handlers.wsgi.WSGIHandler()

Here are the screenshots of my Web section, Files Section, And errors

websection

filessection

modulenotfound

migratenotfound

One thing I should mention first -- it's a bit unusual that you've put your source code for the website inside the virtualenv directory. I'd recommend against doing that; the normal setup is that you'd have mysite in your home directory (that is, /home/rickson/mysite) and the virtualenv separate. I don't think this is what's causing the problem here, but having things in unusual locations is likely to make it harder for other people to help with debugging because their expectations about where stuff is won't apply.

Regarding the WSGI file, it looks like the formatting is messed up in the version you posted above -- some important code is commented out. From the stack trace you posted, it looks like you probably have the right stuff in the real file, but just for clarity, what you need is this:

# +++++++++++ DJANGO +++++++++++
# To use your own Django app use code like this: 
import os import sys

path = '/home/rickson/.virtualenvs/ypfvirtualenv/python-project/mysite' 
if path not in sys.path:
    sys.path.append(path)


os.environ("DJANGO_SETTINGS_MODULE", "mysite.settings")

## Uncomment the lines below depending on your Django version
###### then, for Django >=1.5: 
from django.core.wsgi import get_wsgi_application 
application = get_wsgi_application()
###### or, for older Django <=1.4
#import django.core.handlers.wsgi
#application = django.core.handlers.wsgi.WSGIHandler()

Finally, regarding the ImportError: cannot import name 'include', that looks like a Django version mismatch. Which version do you have installed into the virtualenv? You can find out by running

pip show django

...from a bash console in the virtualenv. Your code causing the error is

from django.urls import include,path

...which I believe is the right code for Django 2.0. If you're using an earlier version, then you'll either need to upgrade Django in the virtualenv, or adjust the code to work with the version you have installed.

            /?????????\    
<<<<<<:>~  <   Yay!          |   
             \_________/

You're right. reinstalling - pip install django==2.0 - did the trick. Thanks for the suggesion and separating the code from the virtual env. I thought the code needs to be kept inside the virtualenv.

Excellent! Glad I could help.

The thing with the virtualenv/code separation is largely because virtualenvs are normally ephemeral things -- because they can't be copied from machine to machine (at least, unless the machines have exactly the same configuration), the normal process is to keep them outside your source code control, and often (when debugging package install problems) to completely delete them and re-create them. Which causes obvious problems if your code is there too ;-)