Lesson 8
Screen 1 of 18
1) Components of a Web application
2) Web frameworks and Flask
3) Installing Python and packages
4) Creating your development environment
5) Building your first local Flask app
6) Running your first Flask app
7) Web application deployment
8) Deploying to PythonAnywhere
Lesson 8
Screen 2 of 18
Lesson 8
Screen 3 of 18
PythonAnywhere is a PaaS provider that can host and run your Flask application in the cloud (Reitz and Schlusser 2016). Watch the video from PythonAnywhere (2013) to learn about their service.
Lesson 8
Screen 4 of 18
A basic, ‘beginner’ user account with PythonAnywhere is free and includes a:
Lesson 8
Screen 5 of 18
Complete the following steps to create a new user account with PythonAnywhere:
Lesson 8
Screen 6 of 18
Your PythonAnywhere user account is setup. Confirm you can access to your PythonAnywhere account by logging in with your chosen login credentials. Stay logged in to your PythonAnywhere account for the remainder of this lesson.
Complete the following steps to create a new Flask Web application on PythonAnywhere.
Lesson 8
Screen 7 of 18
Your new, online, PythonAnywhere Flask Web application is accessable the from the dashboard (shown below).
Lesson 8
Screen 8 of 18
You can make deploying your application easier by consolidating your local Flask Web application files into a single, unified file, called a ‘ZIP file'. To make a ZIP file...
You need to deploy the local Flask application you created in lesson 5 to the PythonAnywhere service.
Deployment will replace your online Flask Web application with your local Flask Web application.
Lesson 8
Screen 9 of 18
Complete the following steps to create a new ZIP file from your local Flask Web application files:
You now have a new ZIP file named ‘app.zip’, inside your local project directory at c:\~\myproject\app\app.zip
c:\~\myproject\
c:\~\myproject\app
Lesson 8
Screen 10 of 18
Upload ‘app.zip’ to PythonAnywhere by completing the following steps
A copy of ‘app.zip’ is now inside your ‘mysite’ directory on PythonAnywhere’s file-system.
Lesson 8
Screen 11 of 18
Complete the following steps to extract the contents of your uploaded ZIP file (‘app.zip’) onto PythonAnywhere’s file-system:
Your Flask Web application files have been uploaded and extracted successfully to PythonAnywhere.
unzip app.zip
exit
Lesson 8
Screen 12 of 18
Direct PythonAnywhere to your extracted files by completing the following steps:
Lesson 8
Screen 13 of 18
project_home = u'/home/firstflaskapp/mysite/
to:
project_home = u'/home/firstflaskapp/mysite/app/
With the editor window open...
from:
from flask_app import app as application
to:
from app import app as application
from:
Your online Flask Web application is configured and ready to run.
Lesson 8
Screen 14 of 18
To run your Flask Web application on PythonAnywhere:
Reload your online Flask Web application whenever you make changes to your online application files. If you modify your local Flask Web application files, upload the changed files to PythonAnywhere and reload your online Web application.
Lesson 8
Screen 15 of 18
The URL for your Flask Web application is listed at the top of the ‘Web’ options menu (after ‘Configuration for [your URL]’), as shown.
Verify your Web application has deployed successfully to PythonAnywhere by copying the URL and pasting it into the address bar of your Web browser. If deployment was successful, you will see the ‘Hello, World!’ message, sent from your online Flask Web application, inside your browser’s window.
You can logout of PythonAnywhere or modify your Web application files online.
You completed lesson 8 on Deploying to PythonAnywhere successfully. You can now:
Lesson 8
Screen 16 of 18
After you have reviewed the useful resources on the next screen, you have finished the course.
Congratulations! We hope you enjoyed learning to develop your First Flask Web application on PythonAnywhere.
Lesson 8
Screen 17 of 18
Lesson 8
Screen 18 of 18
If you have problems using PythonAnywhere, check the PythonAnywhere (2018) help pages for support.
PythonAnywhere's developers also maintain a blog. Their post ‘A beginner’s guide to building a simple database-backed Flask website on PythonAnywhere’ (Thomas 2015) is particularly useful to beginners. The blog is a great resource for learning more about PythonAnywhere.
Microsoft’s (2016) support website provides a useful guide to creating ZIP files in Windows.