December 11
Simple Python Flask Rest API
Setup project folder:
$ mkdir flask-rest-api; cd flask-rest-api
$ python3 -m venv venv
$ source venv/bin/activate
Check your env, make sure it is the version that you should run on:
$ python -V; pip -V
Install flask and packages:
$ pip install flask flask-sqlalchemy marshmallow psycopg2-binary
Generate freeze requirement text file:
$ pip3 freeze > requirements.txt
Create your app.py file
$ touch app.py
Use any code editor to work on your project.
...
December 10
Run your Python Flask app with existing Apache server
If you already have an EC2 with Apache, you can use it to run your Python Flask app.
Install and Enable mod_wsgi:
$ sudo apt-get install libapache2-mod-wsgi-py3 python-dev
$ sudo a2enmod wsgi
Create a Flask app if you don't have one. See my other blog for create / run flask app.
Configure and Enable a New Virtual Host:
$ sudo nano /etc/apache2/sites-available/MyFlaskApp.conf
Add the following conf code...
December 10
Install Flask on Ubuntu 18.04
Check your Python version:
$ python -V
$ python3 -V
Run your Flask app with python 3. You can set your defaul python with python3 if that is what you want with a simple HACK: $ sudo ln -s /usr/bin/python3 /usr/bin/python
Best to run your app in venv, install python venv if not in your system:
sudo apt install python3.x-venv
Create your project folder and create new virutal...