Code Monkey home page Code Monkey logo

flask-webapp's Introduction

Project structure: Tutorial series

Usage & defined routes

python main.py
  • Login: /auth/login
  • Logout: /auth/logout
  • Profile: /auth/profile
  • Register: /auth/register
  • Upload: /file/upload

Prerequisites

The python packages needed to run the webapp can be installed with:

pip install -r requirements.txt

Database migrations

flask-migrate is an extension based on Alembic, a migrations tool for SQLAlchemy. The following instructions use it to first add a migrations folder at the root of the project, then to create a new migration and finally apply it:

  1. Define environment variable: export FLASK_APP=main.py
  2. flask db init
  3. flask db migrate -m "message"
  4. flask db upgrade

Deployment

An instance folder needs to be created at the root of the project to contain database access credentials. For that, instance/config.py will have to contain:

import os


# needed by csrf field in wtforms & user passwords)
SECRET_KEY = os.urandom(32)

# database access
SQLALCHEMY_DATABASE_URI = "postgresql://<user>:<password>@<host>/<database>"

If the password of the user used to login to pgadmin4 was forgotten, it can be reset with:

ALTER USER user_name WITH PASSWORD 'new_password';

The files uploaded through this web application should also be placed inside the instance folder (e.g. inside a photos subdirectory).

Docker

The docker image was deployed on the docker-hub. The following commands were used to build and tag the image, and deploy it to the hub:

docker build -t <hub-user>/<repo-name> .
docker login
docker push <hub-user>/<repo-name>

To download the image on another machine:

docker run <hub-user>/<repo-name>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.