Created
March 24, 2017 12:17
-
-
Save BenAtWide/4376d16441e8ce4730a2784715c1e630 to your computer and use it in GitHub Desktop.
basic wsgi file for PythonAnywhere
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file contains the WSGI configuration required to serve up your | |
# web application at http://simplicat.pythonanywhere.com/ | |
# It works by setting the variable 'application' to a WSGI handler of some | |
# description. | |
# | |
# +++++++++++ GENERAL DEBUGGING TIPS +++++++++++ | |
# getting imports and sys.path right can be fiddly! | |
# We've tried to collect some general tips here: | |
# https://www.pythonanywhere.com/wiki/DebuggingImportError | |
# +++++++++++ HELLO WORLD +++++++++++ | |
# A little pure-wsgi hello world we've cooked up, just | |
# to prove everything works. You should delete this | |
# code to get your own working. | |
HELLO_WORLD = """<html> | |
<head> | |
<title>Python Anywhere hosted web application</title> | |
</head> | |
<body> | |
<h1>Hello, World!</h1> | |
<p> | |
This is the default welcome page for a | |
<a href="https://www.pythonanywhere.com/">PythonAnywhere</a> | |
hosted web application. | |
</p> | |
<p> | |
Find out more about how to configure your own web application | |
by visiting the <a href="https://www.pythonanywhere.com/web_app_setup/">web app setup</a> page | |
</p> | |
</body> | |
</html>""" | |
def application(environ, start_response): | |
if environ.get('PATH_INFO') == '/': | |
status = '200 OK' | |
content = HELLO_WORLD | |
else: | |
status = '404 NOT FOUND' | |
content = 'Page not found.' | |
response_headers = [('Content-Type', 'text/html'), ('Content-Length', str(len(content)))] | |
start_response(status, response_headers) | |
yield content.encode('utf8') | |
# Below are templates for Django and Flask. You should update the file | |
# appropriately for the web framework you're using, and then | |
# click the 'Reload /yourdomain.com/' button on the 'Web' tab to make your site | |
# live. | |
# +++++++++++ VIRTUALENV +++++++++++ | |
# If you want to use a virtualenv, set its path on the web app setup tab. | |
# Then come back here and import your application object as per the | |
# instructions below | |
# +++++++++++ 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 sys | |
# | |
#path = '/home/simplicat/path/to/my/app | |
#if path not in sys.path: | |
# sys.path.append(path) | |
# | |
#from my_wsgi_file import application | |
# +++++++++++ DJANGO +++++++++++ | |
# To use your own django app use code like this: | |
#import os | |
#import sys | |
# | |
## assuming your django settings file is at '/home/simplicat/mysite/mysite/settings.py' | |
## and your manage.py is is at '/home/simplicat/mysite/manage.py' | |
#path = '/home/simplicat/mysite' | |
#if path not in sys.path: | |
# sys.path.append(path) | |
# | |
#os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.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() | |
# +++++++++++ FLASK +++++++++++ | |
# Flask works like any other WSGI-compatible framework, we just need | |
# to import the application. Often Flask apps are called "app" so we | |
# may need to rename it during the import: | |
# | |
# | |
#import sys | |
# | |
## The "/home/simplicat" below specifies your home | |
## directory -- the rest should be the directory you uploaded your Flask | |
## code to underneath the home directory. So if you just ran | |
## "git clone [email protected]/myusername/myproject.git" | |
## ...or uploaded files to the directory "myproject", then you should | |
## specify "/home/simplicat/myproject" | |
#path = '/home/simplicat/path/to/flask_app_directory' | |
#if path not in sys.path: | |
# sys.path.append(path) | |
# | |
## After you uncomment the line below, the yellow triangle on the left | |
## side in our in-browser editor shows a warning saying: | |
## 'application' imported but unused. | |
## You can ignore this error. The line is necessary, and the variable | |
## is used externally. | |
#from main_flask_app_file import app as application | |
# | |
# NB -- many Flask guides suggest you use a file called run.py; that's | |
# not necessary on PythonAnywhere. And you should make sure your code | |
# does *not* invoke the flask development server with app.run(), as it | |
# will prevent your wsgi file from working. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment