Today we will go over how one can deploy their Flask app with PythonAnywhere .
Click learn more to discoveirng more information about WebSanctuary.
Learn moreTools Needed:
1) A functional Flask Application
2) An account with PythonAnywhere
The Flask Application That Will Be Hosted
(flask_app/templates/index.html) HTML Code:
<!DOCTYPE html>
<html>
<head>
<title> Flask App Tutorial </title>
</head>
<body>
<h1>Flask App Tutorial</h1>
</body>
</html>
(flask_app/app.py) Python Code:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
if __name__ == "__main__":
app.run(debug=False)
End Result:
After creating your account, go to the "Web" tab.
Then create your new webapp!
You will then be prompted to create a web app. Please follow the directions carefuly.
After this, navigate to the files tab. You will notice that you see a flask_app.py file. Delte this file and then upload your own file Python file.
Navigate back to the files section. The GUI on the left will show a folder called "my site". Navigate into this directory. Click the mysite directory.
Now that you are inside the "my-site" folder, you are now able to create files inside this folder. To complete the next step, you must create a folder called templates and inside that folder upload the HTMl files that you require.
Once navigated/clicked into the templates file you will be able to upload your HTML files.
Navigate to the Web Tab and scroll down. View the image below to navigate to the WSGI Configuration file.
Once you have clicked on the file, you will be prompted to edit the file. When editing, change "flask_app" to the name of your Python file. In this case, we will be changing it to "app" because our Python file is "app.py".
The underlined word is the word that should be changed from flask_app to the name of your Python application. If your python application is 'app.py', you must input 'app' in place of 'flask_app'.
Congratulations, your app is being hosted with PythonAnywhere! The URL that you have been given now leads to your website.