Code Monkey home page Code Monkey logo

microblog's Introduction

Overview

Flask is a python framework that is used to build web applications. It uses the Jinja2 templating engine to render dynamic html content. This project follows the tutorial from this blog.

References

(a) Flask basic overview
(b) app.run() vs flask run

Discussion

The basic structure of the project is outlined below.

microblog/
├── .flaskenv
├── .venv/
├── microblog.py
├── config.py
├── tests.py
├── requirements.txt
├── app/
│   ├── __init__.py
│   ├── routes.py
│   ├── forms.py
│   ├── errors.py
│   └── models.py
├── templates/
│   ├── index.html
│   └── 404.html
└── logs/

Server Startup

The recommended way to start the application is using the flask run command. The command starts a development server, loads environment variables from the .flaskenv file, and runs the python file defined by the FLASK_APP environment variable in .flaskenv. See reference (a) for further reading on flask run.

# .flaskenv
export FLASK_APP=microblog.py          # Name of application file
export FLASK=[development|production]  # Toggle development or production mode (among others)

If running on a remote server, use flask run -h 0.0.0.0 -p xxxx.

In this case, microblog.py imports the app module, calling app/__init__.py. This file will create the application object; import configuration data from config.py; initialize database and migrations objects; initialize the login manager; setup the mail server and application logging; and import routes.py, models.py, and errors.py.

Configuration Data

Application configuration data is stored in config.py. For some configuration information, the file will first look check if any environment variables are set matching the configuration item. If not, config.py sets it. Other configuration information is located here for convenience.

Application Web Pages

All of the different URLs for the application are handled in routes.py. Each page is handled by a view function, which is mapped to a URL for the pages contained in app/templates/. When the client's browser requests a page, flask runs the corresponding view function for the page, passing any dynamic content to the template. The template is displayed using the Jinja2 templating engine. Each template is primarily standard html, with the expected dynamic content from routes.py encapsulated in double curly braces. Control statements, such as for loops or inclusion statements (e.g., import, #include) are denoted by {% %} markers.

Forms

A web page often accepts input from a user in some format. Where input is required, forms are implemented. Forms rely on the WTForms package and its associated lightweight flask warapper, Flask_WTF.

  • The Form is the key building block of any web form
  • Each Form contains several Fields, such as IntegerField or StringField
  • Every Field has a Widget, which represents the actual rendered object
  • Fields contain a list of Validators, such as DataRequired()

Packages

Simply put, there are a huge number of python packages that are required to build a flask application. Each package, its dependencies, and a brief description of the purpose of the package is provided here.

Package Name Requires Purpose
alembic
Babel
blinker
certifi
charset-normalizer
click
colorama
dataclasses
defusedxml
dnspython
dominate
elasticsearch
email-validator
Flask Werkzeug, Jinja2, itsdangerous, click Python web application framework
Flask-Babel
Flask-Bootstrap
Flask-HTTPAuth
Flask-Login
Flask-Mail
Flask-Migrate
Flask-Moment
Flask-SQLAlchemy
Flask-WTF
greenlet
httpie
idna
importlib-metadat
itsdangerous Secure data signing
- Handles flasks's session cookie
Jinja2
langdetect
Mako
MarkupSafe
Pygments
PyJWT
PySocks
python-dateutil
python-editor
pytz
redis
requests
requests-toolbelt
rq
six
SQLAlchemy
typing-extensions
urllib3
visitor
Werkzeug dataclasses Python implementation of Web Server Gateway Interface (WSGI)
- Password hashing
WTForms
zipp

microblog's People

Contributors

twcarbone avatar

Watchers

 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.