Forums

Getting my first app to work on your hosting environment

Hi I have successfully moved my files from local PC to your hosting environment and if I then go to my "homepage" without changing anything, I get the success message. lz7cjc.pythonanywhere.com.

I have uploaded a project called Recharge and my WSGI file is in recharge/recharge.and my app is called daypass which sits under the top level recharge folder, so recharge/daypass

I have amended the WSGI file to include the following:

# +++++++++++ CUSTOM WSGI +++++++++++
# If you have a WSGI file that you want to serve using PythonAnywhere, perhaps
# in your home directory under version control, then use something like this:
#
import os
import sys
#
path = '/home/lz7cjc/recharge/recharge'
if path not in sys.path:
    sys.path.append(path)
#
from my_wsgi_file import daypass as application

and

# +++++++++++ DJANGO +++++++++++
# To use your own django app use code like this:
import os
import sys
#
## assuming your django settings file is at '/home/lz7cjc/mysite/settings.py'
path = '/home/lz7cjc/recharge/daypass'
if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'recharge.settings'
#
## then, for django >=1.5:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

what have I done wrong? I am a bit confused by all the similar sounding folders and also the presense of a second WSGI file that I am meant to configure.

The site is simple - just a single responsive page with an embedded map and I would dearly love to see it on the web!

thanks for your help Nick

What does your error log say?

thanks for getting back to me:

Traceback (most recent call last):
2015-02-05 13:10:17,624 :  File "/bin/user_wsgi_wrapper.py", line 130, in __call__
2015-02-05 13:10:17,625 :    self.error_log_file.logger.exception("Error running WSGI application")
2015-02-05 13:10:17,625 :  File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2015-02-05 13:10:17,625 :    self.error(msg, *args, **kwargs)
2015-02-05 13:10:17,625 :  File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2015-02-05 13:10:17,625 :    self._log(ERROR, msg, args, **kwargs)
2015-02-05 13:10:17,625 :  File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2015-02-05 13:10:17,626 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2015-02-05 13:10:17,626 :  File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2015-02-05 13:10:17,626 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2015-02-05 13:10:17,626 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2015-02-05 13:10:17,626 :    self.threadName = threading.current_thread().name
2015-02-05 13:10:17,626 :  File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2015-02-05 13:10:17,627 :    return _active[_get_ident()]
2015-02-05 13:10:17,627 :  File "/bin/user_wsgi_wrapper.py", line 122, in __call__
2015-02-05 13:10:17,627 :    app_iterator = self.app(environ, start_response)
2015-02-05 13:10:17,627 :  File "/bin/user_wsgi_wrapper.py", line 136, in import_error_application
2015-02-05 13:10:17,627 :    raise e
2015-02-05 13:10:17,627 :ImportError: No module named my_wsgi_file

don't know what that means!

[edited by admin: formatting]

From your path and import, you need a file in /home/lz7cjc/recharge/recharge called my_wsgi_file.py? Do you have it there or is it somewhere else?

Have a look at this for more in-depth understanding of what's going on.

no I have a file called wsgi.py - i have replaced the reference but still get errors:

Traceback (most recent call last):
2015-02-05 15:13:40,817 :  File "/bin/user_wsgi_wrapper.py", line 130, in __call__
2015-02-05 15:13:40,817 :    self.error_log_file.logger.exception("Error running WSGI application")
2015-02-05 15:13:40,818 :  File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2015-02-05 15:13:40,833 :    self.error(msg, *args, **kwargs)
2015-02-05 15:13:40,833 :  File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2015-02-05 15:13:40,834 :    self._log(ERROR, msg, args, **kwargs)
2015-02-05 15:13:40,834 :  File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2015-02-05 15:13:40,834 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2015-02-05 15:13:40,835 :  File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2015-02-05 15:13:40,835 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2015-02-05 15:13:40,835 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2015-02-05 15:13:40,835 :    self.threadName = threading.current_thread().name
2015-02-05 15:13:40,835 :  File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2015-02-05 15:13:40,847 :    return _active[_get_ident()]
2015-02-05 15:13:40,847 :  File "/bin/user_wsgi_wrapper.py", line 122, in __call__
2015-02-05 15:13:40,847 :    app_iterator = self.app(environ, start_response)
2015-02-05 15:13:40,848 :  File "/bin/user_wsgi_wrapper.py", line 136, in import_error_application
2015-02-05 15:13:40,848 :    raise e
2015-02-05 15:13:40,848 :ImportError: No module named my_wsgi_file
2015-02-05 15:13:41,759 :Traceback (most recent call last):
2015-02-05 15:13:41,759 :  File "/bin/user_wsgi_wrapper.py", line 130, in __call__
2015-02-05 15:13:41,759 :    self.error_log_file.logger.exception("Error running WSGI application")
2015-02-05 15:13:41,760 :  File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2015-02-05 15:13:41,760 :    self.error(msg, *args, **kwargs)
2015-02-05 15:13:41,760 :  File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2015-02-05 15:13:41,760 :    self._log(ERROR, msg, args, **kwargs)
2015-02-05 15:13:41,760 :  File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2015-02-05 15:13:41,761 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2015-02-05 15:13:41,761 :  File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2015-02-05 15:13:41,761 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2015-02-05 15:13:41,761 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2015-02-05 15:13:41,761 :    self.threadName = threading.current_thread().name
2015-02-05 15:13:41,761 :  File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2015-02-05 15:13:41,761 :    return _active[_get_ident()]
2015-02-05 15:13:41,762 :  File "/bin/user_wsgi_wrapper.py", line 122, in __call__
2015-02-05 15:13:41,762 :    app_iterator = self.app(environ, start_response)
2015-02-05 15:13:41,762 :  File "/bin/user_wsgi_wrapper.py", line 136, in import_error_application
2015-02-05 15:13:41,762 :    raise e
2015-02-05 15:13:41,762 :ImportError: No module named my_wsgi_file
2015-02-05 15:34:42,738 :/usr/lib/python2.7/threading.py:1160: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
2015-02-05 15:34:42,739 :  return _active[_get_ident()]
2015-02-05 15:34:42,739 :Traceback (most recent call last):
2015-02-05 15:34:42,739 :  File "/bin/user_wsgi_wrapper.py", line 130, in __call__
2015-02-05 15:34:42,739 :    self.error_log_file.logger.exception("Error running WSGI application")
2015-02-05 15:34:42,739 :  File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2015-02-05 15:34:42,752 :    self.error(msg, *args, **kwargs)
2015-02-05 15:34:42,753 :  File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2015-02-05 15:34:42,753 :    self._log(ERROR, msg, args, **kwargs)
2015-02-05 15:34:42,753 :  File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2015-02-05 15:34:42,753 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2015-02-05 15:34:42,753 :  File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2015-02-05 15:34:42,753 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2015-02-05 15:34:42,754 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2015-02-05 15:34:42,754 :    self.threadName = threading.current_thread().name
2015-02-05 15:34:42,754 :  File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2015-02-05 15:34:42,754 :    return _active[_get_ident()]
2015-02-05 15:34:42,754 :  File "/bin/user_wsgi_wrapper.py", line 122, in __call__
2015-02-05 15:34:42,754 :    app_iterator = self.app(environ, start_response)
2015-02-05 15:34:42,754 :  File "/bin/user_wsgi_wrapper.py", line 136, in import_error_application
2015-02-05 15:34:42,754 :    raise e
2015-02-05 15:34:42,754 :ImportError: No module named wsgi

[edited by admin: formatting]

Hang on, I just reread your original post. It looks like you have 2 sections of the WSGI file activated. Why? The only uncommented code you should have in the WSGI file is the stuff that you have under # +++++++++++ DJANGO +++++++++++. The custom section is for custom configs. You should not need to reference a WSGI file that's not in /var/www.

Also, you'll from your Django config, you'll need make sure that you paths match where your settings file is. The paths you have suggest that your settings file is at /home/lz7cjc/recharge/daypass/recharge/settings.py

ah i see - sorry I am blindly hacking this together as only just started to learn how to code.

I now get the default root page appearing at http://lz7cjc.pythonanywhere.com/ but if I do /daypass which is my app name it says file not found. same if I do /recharge

Would those need to be in the URLs file or can I serve static html directly?

on my home environment I run localhost:8000/daypass to get the page appearing that I would like to see

here I am using http://lz7cjc.pythonanywhere.com/daypass

this is what I now have:

path = '/home/lz7cjc/recharge/recharge'
if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'recharge.settings'
#
## 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()

and have tried commenting each of the versions in turn

[edited by admin: formatting]

nothing in the error logs since I made that change

Hey lz7cjc,

The path in your wsgi.py should just be your django project directory. (Change your path to just /home/lz7cjc/recharge)

Notice that your settings module is this path plus the os.environ['DJANGO_SETTINGS_MODULE']. ie. taken together, it is /home/lz7cjc/recharge/recharge/settings. Double check that that is actually correct.

we are definitely getting somewhere - sorry about this. The error I now get is:

:/

usr/lib/python2.7/threading.py:1160: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
2015-02-05 17:29:59,374 :  return _active[_get_ident()]
2015-02-05 17:29:59,374 :Traceback (most recent call last):
2015-02-05 17:29:59,374 :  File "/bin/user_wsgi_wrapper.py", line 130, in __call__
2015-02-05 17:29:59,374 :    self.error_log_file.logger.exception("Error running WSGI application")
2015-02-05 17:29:59,374 :  File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2015-02-05 17:29:59,374 :    self.error(msg, *args, **kwargs)
2015-02-05 17:29:59,374 :  File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2015-02-05 17:29:59,375 :    self._log(ERROR, msg, args, **kwargs)
2015-02-05 17:29:59,375 :  File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2015-02-05 17:29:59,375 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2015-02-05 17:29:59,375 :  File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2015-02-05 17:29:59,375 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2015-02-05 17:29:59,375 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2015-02-05 17:29:59,376 :    self.threadName = threading.current_thread().name
2015-02-05 17:29:59,376 :  File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2015-02-05 17:29:59,376 :    return _active[_get_ident()]
2015-02-05 17:29:59,376 :  File "/bin/user_wsgi_wrapper.py", line 122, in __call__
2015-02-05 17:29:59,376 :    app_iterator = self.app(environ, start_response)
2015-02-05 17:29:59,376 :  File "/bin/user_wsgi_wrapper.py", line 136, in import_error_application
2015-02-05 17:29:59,376 :    raise e
2015-02-05 17:29:59,376 :ImportError: No module named wsgi

[edited by admin: formatting]

Do you mind if I take a look at your code or tweak your wsgi file?

no problem - it is a bit of a mess and I had to hard code some URLs to make it work locally which I know need to be changed. The only file that I am interested in serving is facilities list, for now. Which is in recharge > templates > daypass

Do I need to cut/paste into here or can you access?

I can access. Which version of python and django were you using previously by the way? And did you use a virtualenv on your local machine?

1.7.1 I believe - is there a simple way to check?

manage.py --version

1.7.2

Hey lz7cjc,

I got your app to a state where it is running. The django-registration module that you had doesn't work- it is known to have conflicts with django1.7, so you will have to sort that out on your own.

Note that I have created a virtualenv called Django1.7 for you.

ok thanks - i can remove any postgresql for now so that shouldn't be too hard... thanks for your help