Python django & flask — Robin Wils's website

Last modified: Sat, Oct 22, 2022

Haven’t done this in ages. I am not sure of this is still accurate.

Python Django enviroment setup

# make project directory
mkdir myproject
cd myproject

# create virtual enviroment (=venv)
python3 -m venv django-env

# activate enviroment
. django-env/bin/activate

# install django (in venv)
pip install django

# make new project (in venv)
django-admin startproject myproject

# make a new app (in venv)
cd myproject
python manage.py startapp myapp

# apply migrations (in venv)
python manage.py migrate

# apply specfic app migrations (in venv)
python manage.py makemigrations myapp

# run project (in venv)
cd myproject
python manage.py runserver

# create admin login (in venv)
python manage.py createsuperuser

# exit venv
deactivate

Python Flask enviroment setup

# make project directory
mkdir myproject
cd myproject

# create virtual enviroment (=venv)
python3 -m venv flask-env

# activate enviroment
. flask-env/bin/activate

# install django (in venv)
pip install flask

# create requirements file
pip freeze > requirements.txt

# make new project (in venv)
readonly PROJECT_NAME="fediverse_blogs"
mkdir $PROJECT_NAME $PROJECT_NAME/static $PROJECT_NAME/templates
touch $PROJECT_NAME/__init__.py $PROJECT_NAME/$PROJECT_NAME.py
/bin/cat <<EOM >$PROJECT_NAME.py
from flask import Flask

app = Flask(__name__)

@app.route('/')
@app.route('/index')
def index():
    return 'Hello world!'

if __name__ == "__main__":
    app.run()

EOM

# WTForms
pip install flask-wtf

# make a new app (in venv)
cd myproject
python manage.py startapp myapp

# apply migrations (in venv)
python manage.py migrate

# apply specfic app migrations (in venv)
python manage.py makemigrations myapp

# run project (in venv)
cd myproject
python manage.py runserver

# create admin login (in venv)
python manage.py createsuperuser

# exit venv
deactivate
# get secret
import os
os.urandom(12)