0
votes

So I have created a django site and I wanted to move it from my computer to my server. I set up Django on the server, and used the WSGI configuration. When I try to go to the home page I get an Import Error, It says that the module "myproject.urls" isn't found. It's a Django error, and it looks like it is getting the settings.py file and looking at the setting for ROOT_URLCONF and seeing the right urls file. I created this project with the usual django-admin.py startproject myproject and I just wanted to see if everything was configured correctly, but now I'm getting this error.

Any Suggestions?

3

3 Answers

2
votes

Remove the "myproject" from "myproject.urls". Somehow WSGI addresses the settings as the root, so no need to refer to it again.

1
votes

It sounds like myproject isn't on your path - what happens if you load up a python shell and run import myproject? If that works, what happens when you run import myproject.urls? If only the second import fails, there's a syntax error in your urls.py or one of the files it imports.

1
votes

@Afrowave, you saved a huge headache - thank you from me too!

Further to this - I did a little more digging and wanted to avoid having to amend a dozen files in my app to account for loosing 'myproject.' and the start of every import.

Instead, I found if you do something like this -- you don't have to :)

ROOT = '/home/user/path_to_project_root' # In my case, also the dir that contains media, templates etc
APP_ROOT = '/home/user/path_to_django_project'
sys.path.append(ROOT)
sys.path.append(APP_ROOT)
os.environ['DJANGO_SETTINGS_MODULE'] = 'django_project.settings'

Hope this helps someone in future.