Project 3 - Web App Hosting
Goals
- Build a simple Django application
- Configure a web server at Python Anywhere
- Deploy a web app at Python Anywhere
- Serve static media
Steps
Get Ready
- Create a running application (week3/Superhero)
- Build a new Superhero app
- My Superhero App
- Sign up for an account at Python Anywhere
Setup your web server
- 1 - Create a virtual environment at Python Anywhere
- 2 - Install Django
- 3 - Git Clone
- 4 - Create Web App
- 5 - Debug and Test
Step 1 - Create a virtual environment at Python Anywhere
- Create an isolated python environment
- mkvirtualenv --python=/usr/bin/python3.8 .venv
- Activate the environment
- source .venv/bin/activate
Step 2 - Install Django in the environment
- Activate the virtual environment
- Install and test Django
- pip install django
- pip list
- which django-admin (Will list a path for django-admin)
Run Terminal Window
- Select "Consoles, New console, Bash"
- pwd
- cd
- ls -al
Step 3 - Clone your git repository
- Visit your Github Repo
- Clone your repo (this is mine)
- git clone https://github.com/Mark-Seaman/BACS350.git
Step 4 - Create Web App
Create Web App
- Visit your main page
- Login to Python Anywhere account
- Bookmark this page on your bookmark toolbar
- Select Web tab in top menu
Configure the Code Settings
- Your Python Anywhere account supports one free Web App
- Apps on free accounts will shut down after every three months
- Click on "Run until 3 months from today" button
- This is not a problem for when you are actively developing code
Configure Web App
- Find your source code
- Modify your code for Python Anywhere
- Create WSGI connection
- Allow host at "markseaman.pythonanywhere.com"
- Setup static server
Configure the Code Startup
- Edit WSGI Python File
WSGI.py - Web Service Gateway Interface
/var/www/markseaman_pythonanywhere_com_wsgi.py
# +++++++++++ DJANGO +++++++++++
# To use your own django app use code like this:
import os
import sys
## assuming your django settings file is at '/home/markseaman/BACS350/week3/Superhero/settings.py'
## and your manage.py is is at '/home/markseaman/BACS350/week3/Superhero/manage.py'
path = '/home/markseaman/BACS350/week3/Superhero'
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'config.settings'
## then:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Python Anywhere Static Files
Python Anywhere Database
- Start with MySQL, switch to PostGres if needed
Step 5 - Debug and Test
Startup the Server
- Run the server http://markseaman.pythonanywhere.com/
- Button labeled "Bounce the server" on the above screen shot
- Browse to http://markseaman.pythonanywhere.com/
Debug and Test
- Browse to http://markseaman.pythonanywhere.com/ for Mark's Site
- Browse to http://YOUR_USER.pythonanywhere.com/ for Your Site
- Debug your application code
Read the Log
Register your server
- Make sure this address is set in Sensei
- Example: http://markseaman.pythonanywhere.com/
Requirements
- Your page must be available at http://YOUR_USER.pythonanywhere.com/
- It must contain info about superheroes
- You must load images with a static server