Loading...
 
Flask is considered more Pythonic than the Django web framework because in common situations the equivalent Flask web application is more explicit.

Flask Web Project

Flask Setup

  • Python Development Environment
  • Installation - Flask depends on some external libraries, like Werkzeug and Jinja2. Werkzeug is a toolkit for WSGI, the standard Python interface between web applications and a variety of servers for both development and deployment. Jinja2 renders templates.
  • Quickstart - Eager to get started? This page gives a good introduction to Flask. It assumes you already have Flask installed. If you do not, head over to the Installation section.

Flask Project Structure

How To Structure Large Flask Applications - There are many methods and conventions for structuring Python web applications. Although certain frameworks are shipped with tools (for scaffolding) to automate — and ease — the task (and the headaches), almost all solutions rely on packaging / modularizing applications as the codebase gets distributed logically across related files and folders.

Module Basics

Module Name = mymodule

__init__.py

controllers.py
from flask import Blueprint, render_template, abort
from jinja2 import TemplateNotFound

mymodule = Blueprint('mymodule', __name__,
                        template_folder='templates')

@mymodule.route('/', defaults={'mymodule': 'index'})
@mymodule.route('/<mymodule>')

def show(mymodule):
    title = 'My Module'
    try:
        return render_template('mymodule/%s.html' % mymodule,title=title)
    except TemplateNotFound:
        abort(404)
models.py

forms.py

Module Templates

/templates/mymodule/index.html
{% extends "base.html" %}
{% block title %}{{ title }}{% endblock %}

{% block page_content %}
    <div class="page-header">
        <h1>My Module</h1>
    </div>
{% endblock %}

Template

Jinja2

Jinja2 is a modern and designer-friendly templating language for Python, modelled after Django’s templates.1

JavaScript Frontend

Vue.js

Vue.js is an open-source progressive JavaScript framework for building user interfaces. Integration into projects that use other JavaScript libraries is made easy with Vue because it is designed to be incrementally adoptable. Vue can also function as a web application framework capable of powering advanced single-page applications.2

Extensions

Flask-Bootstrap

Flask-Bootstrap packages Bootstrap into an extension that mostly consists of a blueprint named ‘bootstrap’. It can also create links to serve Bootstrap from a CDN.3

Flask-Vue

Flask-Vue packages Vue.js and many extended scripts into an extension.4

Flask-SQLAlchemy

Flask-SQLAlchemy - The SQLAlchemy SQL Toolkit and Object Relational Mapper is a comprehensive set of tools for working with databases and Python. It has several distinct areas of functionality which can be used individually or combined together. 5

Flask-WTF

Flask-WTF - Simple integration of Flask and WTForms, including CSRF, file upload and Recaptcha integration.6

Last edited by MichaelAlber .
Page last modified on Saturday December 22, 2018 17:55:13 UTC.