Forums

Getting the my django app online

Hi There

I have been struggling for sometime now to get my django app online, I have played around with my config file and all i get is "Oops something has gone wrong with an Error code: Unhandled Exception"

I successfully activate my environment, zero errors it ran the default hello world message, but the minute I start configuring the custom WSGI part or the Django part in the config file nothing works and the editor does not provide me with any errors such that I know whats wrong.

After each change to the config I did reload

Here is my directory/

--home/myusername/

  -- projectfolder/
          -- env/
          -- templates/
          -- src/
                 -- manage.py
                 -- myrpoject/
                         -- __init__.py
                         -- settings.py
                         -- wsgi.py

Any help would be greatly appreciated!

Is there anything in the error log on the Web tab?

Also, this wiki article has some good debugging tips: https://www.pythonanywhere.com/wiki/DebuggingImportError

Okay so I went through the error and server logs and I the link that was suggested above, when I print my sys.path it is all inside of my virtualenv because it is activated because I use a virtualenv but for some reason it does not seem to be able to now pick up my settings file....

Taken into account my directory mentioned above, here is what my WSGI config file looks like atm

#virtualenv activation
#path to the activate this py file in the virtualenv

activate_this = '/home/username/projectfolder/env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

##the above activation of my virtual environment gives me no errors


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

import os
import sys

path = '/home/username/projectfolder/src/myrpoject/'
if path not in sys.path:
    sys.path.append(path)

print sys.path

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

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

The error I am getting in my error log is: ImportError: Could not import settings 'myrpoject.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named myrpoject.settings

I ran sum tests where I even added 'test/test/test' to the path and printed it and it was not found, so maybe nothing is getting appended to my path? I dont know, please help

Thank you

[edited by admin -- the old activate_this / exec system is now deprecated -- check out the overview on the wiki of the new virtualenv system.]

From your WSGI file, your settings.py file should be at /home/username/projectfolder/src/myrpoject/myrpoject/settings.py. Check that that is true.

I did not structure my directory like that. I am pretty sure the problem lies with appending the path to my sys.path, because when i print sys.path i cannot find that path there? Is saw in previous posts that you guys looked at someone's files in order to help him, can you guys do that for me aswell? I really don't mind, I would just like to get this site up ASAP

The settings module path in your WSGI app is wrong. It should just be settings based on your file structure. The log line with your sys.path is truncated and that's why you don't see the path you're adding in the WSGI file.

Still getting the exact same problem after changing it

Here is my python anywhere WSGI config file

activate_this = '/home/luanvdw/iamluan_official/env/bin/activate_this.py' execfile(activate_this, dict(file=activate_this))

import os import sys

path = 'home/luanvdw/iamluan_official/src/iamluan' if path not in sys.path: sys.path.append(path)

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

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

Here is my local wsgi file...

import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

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

My path to my settings file.... /home/luanvdw/iamluan_official/src/iamluan/settings.py

I see 2 problems there:

  1. You're missing a slash in your path. 'home/luanvdw/iamluan_official/src/iamluan' should be '/home/luanvdw/iamluan_official/src/iamluan'

  2. If you have /home/luanvdw/iamluan_official/src/iamluan on your path and your settings file is at /home/luanvdw/iamluan_official/src/iamluan/settings.py then your DJANGO_SETTINGS_MODULE must be settings. This also keeps your PythonAnywhere app more like your local one.

Thank you that problem is now resolved, now i get the following error. ImportError: No module named iamluan.urls I have this configured in my settings.py

ROOT_URLCONF = 'iamluan.urls'

WSGI_APPLICATION = 'iamluan.wsgi.application'

is there a specific convention one needs to following here because on my localhost, when i python src/manage.py runserver, everything works?

Thank you for the help!