Git Product home page Git Product logo

flask4ds's Introduction

flask-4-ds

Using Flask to create a full-featured webapp for serving data products

Two ways to run the flask app

  • FLASK_APP=app.py FLASK_DEBUG=1 flask run
  • python app.py with app.run() in app.py

The decorator @app.route('/<endpoint>') is used to declare functions that return html (or rendered templates) when the client requests an endpoint.

render_template helps pass raw html or rendered Jinja templates.

  • it accepts data that can be used to render the page

Use url_for as far as possible to access resources under static/ for example You can also pass the function name associated with a route.

Create a SECRET_KEY using secrets.token_hex(16) from the secrets library and assign it to app.config

flask_sqlalchemy lets you declare table schemas as classes and work seamlessly with any database backend.

Then, we can fill these tables using db.session.add(<Object of table-class>) The class can be used to query data as User.query.all() or User.query.filter_by(<condition>).all()

For security, passwords must be hashed using the flask-bcrypt library. Bcrypt objects have methods like generate_password_hash and check_password_hash that are useful.

Use flask-login to manage user sessions

Useful functions

from flask import (
    Flask,                  
    render_template,
    url_for,
    flash,
    redirect,
    request
)

from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt

from flask_login import (
    LoginManager,
    UserMixin,
    login_user,
    current_user,
    logout_user,
    login_required
)

from flask_wtf import FlaskForm

from flask_wtf.file import FileField, FileAllowed

from wtforms import (
    StringField,
    PasswordField,
    SubmitField,
    BooleanFielda
)

from wtforms.validators import (
    DataRequired,
    Length,
    Email,
    EqualTo,
    ValidationError
)

flask4ds's People

Contributors

dushyantkhosla avatar

Watchers

 avatar  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.