Flask Dashboard Argon - deploy on PythonAnywhere
Hello Coder,
I'm writing this article based on my first experience deploying an app on PythonAnywhere platform. Until now I was using my own VPS to release Flask apps into the wild. Here is what I've learned.
Account features
PythonAnywhere offers a free plan, quite limited sometimes, but overall ok, for a learning or demo project (like this one). Using a free plan you will get:
- Two consoles. I've chosen
bash
andpython 3.6
to prepare the app environment and install the dependencies. - The Https certificate, signed by COMODO
- HTTP to HTTPS redirect
Setup the app
By default, the platform create an initial app starter __flask_app.py template. Note: This file should be edited or replaced with your own bootstrapper. Because my app is published on Github, the first step was to clone the sources and after install the dependencies and create the database.
$ git clone https://github.com/app-generator/flask-argon-dashboard.git
$ pip install -r requirements.txt
$ flask shell
$ >>> from app import db
$ >>> db.create_all()
At this point, the app has the environment up & running, and the database created. To activate the deployment, we need to manually trigger the deployment:
First Run
The first deploy was successfull, and the app is running as expected, without errors:
Adding the sitemap.xml
To enable the Google indexing, a few files must be added to the subdomain:
- sitemap.xml
- google verification file
To solve this problem, I've updated the views.py (app routing definitions) to handle the sitemap request:
import os
from flask import send_from_directory
# handle the new route
@app.route('/sitemap.xml')
def sitemap():
return send_from_directory(os.path.join(app.root_path, 'static'), 'sitemap.xml')
This handle is fairly simple, Flask will return the content of sitemap.xml, saved in the root of static directory app / static / sitemap.xml
.
Resources
- Flask Dashboard Argon PythonAnywhere Live Demo
- Flask Dashboard Argon - app info
- Flask Dashboard - Documentation
- The source code, published on Github
Thank you for reading!