Forums

As a newbie I need some help getting my app online.

Hello. I have been playing around with Django for a while, and would like to be able to put an application online. PythonAnywhere seems like the most user-friendly option that I have found, but I still don't quite get how it works. I think my problem lies with not fully understanding the concept of WSGI files and virtualenv.

I use Python 2.7 and Django 1.7. So from what I understand I need to be using a virtualenv.

My local environment is like this:

myappENV (my virtualenv)

  • bin
  • include
  • lib
  • myapp

and myapp looks like this https://github.com/Gobias1337/wings

So I have a virtualenv locally. On PythonAnywhere I went through the steps outlined here https://www.pythonanywhere.com/wiki/VirtualEnvForNewerDjango using Django 1.7 instead of 1.6.

Then I went to the console and cloned the above app from github. I have been trying to configure the wsgi file linked to from the web tab. Both uncommenting and playing around with the path for CUSTOM WSGI and DJANGO, but without luck.

What am I missing and/or doing wrong? I have been used to Google App Engine, where you just press deploy, and magic happens. So I just need some help getting this to work, as I have been really happy with Django and PythonAnywhere seems like a great host.

I assume you're remembering to 'reload web app' after any changes...

Yes you assumed correctly. I forgot to add that.

This wiki page has some help for common issues with wsgi files: https://www.pythonanywhere.com/wiki/DebuggingImportError

Let me know if that helps? Or if it shows up any helpful information we can use to debug?

Kind of. I can get the stuff in the guide to work. But I still can't get it to work.

This is my wsgi file from the Webs tab:

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

# assuming your django settings file is at '/home/skoer/mysite/settings.py'
path = '/home/skoer/wings/wings/settings.py'
if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'wings.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

My PythonAnywhere structure:

|--virtualnvs/
    |--django17/
    |--wingsENV
|--Dropbox/
|--wings / <-- My app
    |--.git/
    |--.idea/
    |--main/
    |--wings/
        |--__init__.py
        |--settings.py
        |--urls.py
        |--wsgi.py
    |--__init__.py

My error log: http://pastebin.com/fP975uwL My server log: http://pastebin.com/XsaAZuv2

It says it can't find settings.py in sys.path. But this is my sys.path: enter image description here

Your path in the WSGI file is wrong. You should be using path = '/home/skoer/wings/. Assuming that the original path is actually pointing to your settings.py file.

What would be my original path in this situation?

I tried changing the path in the WSGI file:

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

# assuming your django settings file is at '/home/skoer/mysite/settings.py'
path = '/home/skoer/wings/'
if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'wings.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Still the same error in the error.log.

Ah. I just noticed that you're using Django 1.7 in a virtualenv, but I don't see the activation code in your WSGI file. Go back to https://www.pythonanywhere.com/wiki/VirtualEnvForNewerDjango and put the code to activate your virtualenv in.

Ah yes. I did not realize that makes sense. It's still not quite working. Should myapp be in the same folder as the /.virtualenvs/my_virtual_env? But the error "ImportError: Could not import settings 'wings.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named settings". So I think there is still something wrong with my file structure. Are you able to access my dashboard, or else review the file structure I listed above? Thanks for the help so far btw.

This is puzzling. The directory structure looks correct. As an experiment, could you create a new virtualenv based off the old one and try using that for your app?

I'm not exactly sure what you mean with

create a new virtualenv based off the old one

But I went through the https://www.pythonanywhere.com/wiki/VirtualEnvForNewerDjango again. Adding a new costum Python 2.7 application in the Web tabs as well as creating a new virtualenv through the online console and installing Django 1.7.1 in it. I skipped the step with "django-admin.py startproject mysite". Because I already cloned an app from github as mentioned in my first post. My "/var/www/skoer_pythonanywhere_com_wsgi.py" file now looks like this:

activate_this = '/home/skoer/.virtualenvs/wings_venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

import os
import sys

path = '/home/skoer/wings/'
if path not in sys.path:
    sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'wings.settings'

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

I feel like I should be putting my app into the actual virtualenv, in this case wings_venv, but I guess that's what the wsgi file is for?

EDIT: With a bit of inspiration from this thread I tried changing my wsgi file to:

### activate and import omitted ### 
path = '/home/skoer/wings/wings'
if path not in sys.path:
    sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

This seems like it finding the settings.py file, because this gives me a new import error (ImportError: No module named main) for my "main" app, which is the app I have created in my Django project. This is weird as my "main" app does have an init.py file. This is the new error log: http://pastebin.com/WctAkCGY

Also when trying to run the wsgi-file in bash I get the following result: http://pastebin.com/zNxQff8Z

I don't know what was going on there, but when I added the path to the beginning of sys.path, everything started working. I'm extremely puzzled.

Aha! Well that's a good find, however little sense that it makes. I hope this will function as a permanent "fix". Thanks for the help.