Menu
e-lo
  • Home
    • Tech
    • Inspiration and about
  • Database
    • T-SQL
    • SQL Server quick
    • SQL server docs
    • MySql quick sheet
    • Postgre
    • InfluxDB
  • Programming
    • Automating the boring stuff
    • Python 101
    • Python Docs
    • Python Logging
    • cSharp Overview
    • Powershell Latest
    • Powershell 4 lang ref
    • MS Azure PS ref
    • MS Azure CLI ref
  • Azure
    • AZ-104-MS Azure Administrator 101 quick ref
    • AZ-104 Lab
    • MS Windows virtual machines in Azure
    • MS ARM Docs
    • MS ARM Tutorial
    • MS Deployment scripts (intern/extern)
    • ARM Quickstart
    • MS ARM templates 4h
  • Az Adm
    • AD 101
    • Governance and Compliance 102
    • Administration 103
    • Virtual Networking 104
    • Storage 107 (With table (NoSQL and more))
    • Virtual Machines 108
    • Azure Virtual Machines 101
    • Monitor VM (and market)
  • Linux
    • Top CMD’s
    • Useful CMD Linux
    • ss64 Linux
    • Ubuntu
    • 30 things Ubuntu 18.04
  • Zen
    • Not thinking about anything is Zen
e-lo

Python and Flask

Posted on July 26, 2018November 19, 2018 by espenk

I have been learning flask for about 1 year now.

It has been fun, frustrating at times and I wish I would have finished the full documentation for it. But at least now I know how the different parts fit together, and all the “magic” that is inculde in Django is a developer’s choice when using flask.

But what a great micro web framework to use!

Flask is super easy to setup and works great if you are using RAD (Rapid-application development) or have a medium to small size app, it might work really good for bigs apps also, but then there is a lot of choices to consider for extensions and libraries to use.

  • Pip install flask in your env
  • Make a flask app
  • Make a function with a route and then head to localhost:port/route

from flask import Flask, render_template

app = Flask(__name__)

@app.route(“/”)

def index()

#return txt

return “hello world”

#return html

return render_template(“index.html”) index location app/templates/index.html

 

Good tips for bigger apps, use blueprints in flask.

But now I wanna try and learn Django for e-lo.

Short about flask

Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries. It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions. However, Flask supports extensions that can add application features as if they were implemented in Flask itself. Extensions exist for object-relational mappers, form validation, upload handling, various open authentication technologies and several common framework related tools.

testit.tech with flask:

Bootstrap menu:

Login manger:

Note admin, with get all, get topic, new note, edit note and delete note:

Note get topic:

Note add, new note:

Note edit:

Pygal library testing:

pip freeze > requirements.txt

alembic==0.9.10
click==6.7
dominate==2.3.1
Flask==0.12.2
Flask-Bootstrap==3.3.7.1
Flask-Login==0.4.1
Flask-Migrate==2.2.1
Flask-SQLAlchemy==2.3.2
Flask-WTF==0.14.2
future==0.16.0
futures==3.2.0
gunicorn==19.7.1
itsdangerous==0.24
Jinja2==2.9.6
Mako==1.0.7
MarkupSafe==1.0
pygal==2.4.0
python-dateutil==2.7.3
python-editor==1.0.3
six==1.11.0
SQLAlchemy==1.2.9
visitor==0.1.3
Werkzeug==0.12.2
WTForms==2.1

testit.tech was developed with:

  • Flask, Python micro webframwork
  • Jinja2 for templating, html
  • Bootstrap
  • Gunicorn webserver
  • Nginx, reverse proxy
  • Digital Ocean for hosting with linux
  • A blog and a note-app was developed

 

Source code for testit.tech:

https://github.com/spawnmarvel/testit.tech2

 

 

The text below is not part of tutorial, for internal reference only.

Install Nginx, remove default site, create your site, load gunicorn:

nginx pdf

Good to know:

Envs:

source/bin/activate

deactivate

Gunicorn:

wsgi.py:

from app import app

if __name__==”__main__”:

app.run()

(env) gunicorn –bind 0.0.0.0:port wsgi:app

Templates / static not loading after SFTP, stop / start gunicorn

Linux:

sudo lsof -i:port

sudo lsof -i:8000

kill pid

Not finding pid, pkill gunicorn

More on Gunicorn:

Thread

100

Workers increase, things got messed up

https://stackoverflow.com/questions/35837786/how-to-run-flask-with-gunicorn-in-multithreaded-mode

Hang in guniorn, showing old data from views (even though the code changed), cache issue, reboot server.

To reboot immediately you have to specify either of the cmds:

sudo shutdown -r 0

sudo shutdown -r now

 

 

 

RSS Azure

  • Azure and HITRUST publish shared responsibility matrix January 14, 2021

RSS Python

  • PEP 651: Robust Stack Overflow Handling January 18, 2021

Cloud

ARM (8) azure (23) cmd (1) Django (4) Docker (1) e-lo (2) Flask (2) Github (9) Grafana (2) Information (1) Information Retrieval (11) JAVA (1) kivy (2) Kotlin (4) linux (11) mobile (2) Natural Language Prossesing (NLP) (2) Net.Core (1) Networking and Security (2) OPC (2) PEP8 (1) Philosophy (3) Python (41) Python Networking and Security (2) Reason (2) RMQ (2) Solr (11) Sql (10) VSC (1) Warframe (2) WMVARE (4) Zabbix (7)

Recent Posts

  • 1 TODO ARM Lab 105 MS (Deployment create a pipeline)
  • 2 TODO MS ARM Template 4h
  • TODO Cryptography with Python – Caesar Cipher
  • 3 TODO Udemy AZ-104 Microsoft Azure Administrator Exam Certification (Scott Duffy)
  • ARM Lab 104 MS (Deployment and more)

Archives

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2021 e-lo | Powered by WordPress & Superb Themes