Giter Club home page Giter Club logo

hello-flask's Introduction

hello-flask

Simple flask program

Python Setup

Craete a pythgon virtual environment to keep the dependencies independent. Activate the enviornemnt and then install flask in it.

sudo apt-get install python3-venv
cd ~/projects
python3 -m venv flask-python-venv
source ~/projects/flask-python-env/bin/activate 
pip3 install flask

Create requirements.txt. Ensure source command above has been run

pip3 install pipreqs
pipreqs ~/projects/hello-flask --force

Run locally

python3 basic.py

If port is already being used then identify the program and stop it.

lsof | grep 5000 
kill <pid>

Deploy to google app engine


-- List projects and ensure correct project is being used
gcloud config list project 

-- deploy the app
gcloud app deploy


Automate appEngine deployment

Enable the AppEngineAdmin and Cloud Build APIs TODO: do this from terraform scripts

Grant App Engine access to the Cloud Build service account

Create a build trigger

More details are at https://cloud.google.com/source-repositories/docs/quickstart-triggering-builds-with-source-repositories

Build trigger failed with an error and I had run the below from the WSL Linux console

PROJECT_ID=xxxxxx

PROJECT_NUMBER=$(gcloud projects list \
  --format="value(projectNumber)" \
  --filter="projectId=${PROJECT_ID}")

gcloud iam service-accounts add-iam-policy-binding \
    ${PROJECT_ID}@appspot.gserviceaccount.com \
    --member=serviceAccount:${PROJECT_NUMBER}@cloudbuild.gserviceaccount.com \
    --role=roles/iam.serviceAccountUser \
    --project=${PROJECT_ID}

Debug

Set the debug to True "app.run(debug=True)". Note down the PIN from the console and then Python allows debug from the webpage. Note that this has to be turned off in production.

Jinja Template

Jinga support passing data from python to html. Pass parameter in render_templtae and refer to it inside 2 sets of curly braces as {{my_variable}}.

Control flow statements reqire to be enclosed in {% %}

Migrate database

From command line

pip3 install Flask-Migrate
export set FLASK_APP=basic.py
flask db init
flask db migrate -m "added column"
flask db upgrade

hello-flask's People

Contributors

finecode avatar

Watchers

James Cloos avatar Satish Babu avatar

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.