Full Stack Web Development with Flask.

Related tags

Flask discover-flask
Overview

Discover Flask

Full Stack Web Development with Flask.

http://discoverflask.com

Build Status

Flask is a micro web framework powered by Python. Its API is fairly small, making it easy to learn and simple to use. But don't let this fool you, as it's powerful enough to support enterprise-level applications handling large amounts of traffic. You can start small with an app contained entirely in one file, then slowly scale up to multiple files and folders in a well-structured manner as your site becomes more and more complex.

real_python_logo

Please note: This is a tutorial series, which is still in progress. The source code is not meant to be used until the end of the series.

Support

Please help us keep this free, open source project going. Purchase the Real Python course. Provide gratitude through Gratipay. Star this repo. Tweet about it. Anything helps. Thank you!

Support via Gratipay

Contents

Part Title Git Tag
1 Setting Up a Static Site (blog post) part1
2 Creating a login page (blog post) part2
3 User Authentication part3
4 Template Inheritance part4
5 Databases part5
6 List Comprehensions N/A
7 Unit Tests part7
8 Deploying to Heroku part8
9 SQLAlchemy part9
10 Configuration part10
11 Secret Key part11
12 Heroku Configuration Settings part12
13 Heroku Postgres Setup part13
14 Local PostgreSQL Setup part14
15 Managing Database Migrations part15
16 Database Downgrades with Flask-Migrate/Alembic part16
17 Virtualenvwrapper part17
18 Password Hashing part18
19 Blueprints part19
20 Blueprints Redux part20
21 User Authentication (part 2) part21
22 Unit Testing with Flask-Testing part22
23 Session Management with Flask-Login part23
24 Testing User Login and Logout part24
25 User Registration (functionality and unit tests) part25
26 Finalize Messaging System part26
27 Test Coverage with coverage.py part27
28 Flask Testing! part28
29 Flask Testing (increase test coverage) part29
30 Continuous Integration part30

You can view the entire video playlist here.

Links

  • Nice Vagrant Instance for Discover Flask, for use with PyJenkinsCI - a test Jenkins Continuous Integration (CI) for Python projects, compatible with Mac OSX and Ubuntu systems. (Thanks, Apollo!)
  • Awesome project, based on the series -> HomeCenter
Comments
  • test cases using () deprecated

    test cases using () deprecated

    For example, self.assertTrue(current_user.is_active()) is used throughout tests. However, self.assertTrue(current_user.is_active) is the correct statement.

    Link for reference: https://stackoverflow.com/questions/32750526/flask-login-raises-typeerror-bool-object-is-not-callable-when-trying-to-overr

    Thanks

    opened by leslie-alldridge 3
  • Confusion

    Confusion

    In app.py

    --connect to database def connect_db(): return sqlite3.connect('posts.db')

    Do we need to include this? Aren't we already exporting it to DATABASE_URL='sql:///posts.db' and we are using SQLAlchemy for this project.I think we should comment this line.

    opened by ragmha 1
  • Sample material does not match the videos

    Sample material does not match the videos

    Hi,

    I started following Part-1 and only found that the downladable examples are different than those used in the course. and the material is about 7 years old.

    Are there any plans to modernate the material to the latest Visual Code and Python 3.9 ?

    Best, Mickey

    opened by tadam98 2
  • How to make a database for each html page in my web application? flask, python, html,sql

    How to make a database for each html page in my web application? flask, python, html,sql

    I'm currently building a flask web application using Microsoft Azure. The basic idea is just a blog for my school which I'm doing as a project. For this web application, I have two html pages. A home page where people just chat and a calendar page. yes not the best ideas but it's sufficient. What i'm wondering is how i select a database for each html page. Since it's like a forum blog type page, I already have the form and the script for that ready but when I enter something, it shows up for all the pages. I've made two databases, database.db for the home page and calendar.db for the calendar page. So far, everything i've been submitting into the forms is going into database.db and not calendar.db for the calendar.html page. So, i've made the database for the calendar page and made a table for it but can't seem to connect it to calendar.db.

    Here is my code:

    app.py

    
    from flask_cors import CORS
    
    from models import create_post, get_posts
    
    
    
    
    
    app = Flask(__name__)
    
    
    
    CORS(app)
    
    
    
    u/app.route('/', methods=['GET','POST'])
    
    def index():
    
    
    
    if request.method == 'GET':
    
    pass
    
    if request.method == 'POST':
    
    name = request.form.get('name')
    
    post = request.form.get('post')
    
    create_post(name, post)
    
    
    
    posts = get_posts()
    
    
    
    return render_template('index.html', posts=posts)
    
    
    
    u/app.route('/calendar.html', methods=['GET','POST'])
    
    def calendar():
    
    
    
    if request.method == 'GET':
    
    pass
    
    if request.method == 'POST':
    
    name = request.form.get('name')
    
    post = request.form.get('post')
    
    create_post(name, post)
    
    
    
    posts = get_posts()
    
    
    
    return render_template('calendar.html', posts=posts)
    
    
    
    if __name__ == '__main__':
    
    app.run(host="0.0.0.0", port=80)
    
    
    
    
    
    

    and then models.py

    
    import sqlite3 as sql
    
    from os import path
    
    
    
    ROOT = path.dirname(path.relpath((__file__)))
    
    
    
    def create_post(name,content):
    
    con = sql.connect(path.join(ROOT, 'database.db'))
    
    cur = con.cursor()
    
    cur.execute('insert into posts (name, content) values(?, ?)', (name, content))
    
    con.commit()
    
    con.close()
    
    
    
    def get_posts():
    
    con = sql.connect(path.join(ROOT, 'database.db'))
    
    cur = con.cursor()
    
    cur.execute('select * from posts')
    
    posts = cur.fetchall()
    
    return posts
    
    
    
    

    and finally my html page for the calendar :

    
    <!doctype html>
    
    <center>
    
    
    
    <head style="color:green; font-family: 'Times New Roman', Times, serif;font-size: 400px;">
    
    <link rel="stylesheet" href="styles.css">
    
    
    
    <font size = "+100">Important Events Coming Up</font>
    
    <title>EcoNet</title>
    
    </head>
    
    <br>
    
    <br>
    
    <br>
    
    
    
    <br>
    
    <table>
    
    <tr>
    
    <th>
    
    <a href="/">Parent Blog</a>
    
    </th>
    
    <th>
    
    <a href="meeting.html">Teachers to Parents</a>
    
    </th>
    
    </tr>
    
    
    
    </table>
    
    
    
    <table >
    
    <thead>
    
    
    
    <tr>
    
    
    
    <td >Mon</td>
    
    <td>Tue</td>
    
    <td>Wed</td>
    
    <td>Thu</td>
    
    <td>Fri</td>
    
    <td>Sat</td>
    
    <td>Sun</td>
    
    
    
    </tr>
    
    
    
    </thead>
    
    
    
    <tbody>
    
    
    
    <tr>
    
    <td >29</td>
    
    <td >30</td>
    
    <td >31</td>
    
    <td>1</td>
    
    <td>2</td>
    
    <td>3</td>
    
    <td>4</td>
    
    </tr>
    
    
    
    <tr>
    
    <td>5</td>
    
    <td>6</td>
    
    <td>7</td>
    
    <td>8</td>
    
    <td>9</td>
    
    <td>10</td>
    
    <td>11</td>
    
    </tr>
    
    
    
    <tr>
    
    <td>12</td>
    
    <td>13</td>
    
    <td>14</td>
    
    <td>15</td>
    
    <td>16</td>
    
    <td>17</td>
    
    <td ></td>
    
    </tr>
    
    
    
    <tr>
    
    <td>19</td>
    
    <td>20</td>
    
    <td>21</td>
    
    <td>22</td>
    
    <td>23</td>
    
    <td>24</td>
    
    <td>25</td>
    
    </tr>
    
    
    
    <tr>
    
    <td>26</td>
    
    <td>27</td>
    
    <td>28</td>
    
    <td>29</td>
    
    <td>30</td>
    
    <td>31</td>
    
    <td >1</td>
    
    </tr>
    
    
    
    </tbody>
    
    
    
    
    
    <h1 style="color:teal; font-family: 'Times New Roman', Times, serif;"> Type Down Below To Remind Anyone of Where and When the Gathering Will Happen</h1>
    
    
    
    
    
    <body style = "background-color:lightgreen;">
    
    <form action='/calendar.html' method='post'>
    
    <input placeholder='Name' name='name'>
    
    <input placeholder='Post Content' name='post'>
    
    <input type='submit' value='Submit'>
    
    </form>
    
    {% for post in posts %}
    
    <div>
    
    {{ post[1] + ': ' + post[2] }}
    
    </div>
    
    {% endfor %}
    
    </body>
    
    </center>
    
    </html>
    
    

    my html is not the best.

    It would be great if you guys could help me. I've made another models.py with different variables and connected them to calendar.html/calendar.db but that hasn't work. I've done a lot of things and followed the same steps i got database.db to work but I can't figure it out.

    Thank you

    opened by EldarU123 1
  • Keyerror

    Keyerror

    Traceback (most recent call last): File "manage.py", line 9, in from solarpi.app import create_app File "/home/amani/Desktop/new/solarpi/solarpi/app.py", line 10, in from solarpi.settings import ProdConfig File "/home/amani/Desktop/new/solarpi/solarpi/settings.py", line 7, in class Config(object): File "/home/amani/Desktop/new/solarpi/solarpi/settings.py", line 8, in Config SECRET_KEY = os_env['SOLARPI_SECRET'] File "/home/amani/Desktop/new/.venv/lib/python2.7/UserDict.py", line 40, in getitem raise KeyError(key) KeyError: 'SOLARPI_SECRET'

    i generated the key but still am getting the same error, can anyone help?

    opened by Amanimasila 3
  • Fixed closing h1 tag

    Fixed closing h1 tag

    When i copied the html from your repo, vscode highlighted a problem with the html with this message Tag must be paired, missing: [ </h1> ], start tag match failed [ <h1> ] hence the fix.

    opened by kellyjoe256 0
Owner
Real Python
Online Python Training: tutorials, video courses, sample projects, news, and more.
Real Python
Flask Project Template A full feature Flask project template.

Flask Project Template A full feature Flask project template. See also Python-Project-Template for a lean, low dependency Python app. HOW TO USE THIS

Bruno Rocha 96 Dec 23, 2022
Full-Stack application that visualizes amusement park safety.

Amusement Park Ride Safety Analysis Project Proposal We have chosen to look into amusement park data to explore ride safety relationships visually, in

Michael Absher 0 Jul 11, 2021
flask-apispec MIT flask-apispec (🥉24 · ⭐ 520) - Build and document REST APIs with Flask and apispec. MIT

flask-apispec flask-apispec is a lightweight tool for building REST APIs in Flask. flask-apispec uses webargs for request parsing, marshmallow for res

Joshua Carp 617 Dec 30, 2022
flask-reactize is a boostrap to serve any React JS application via a Python back-end, using Flask as web framework.

flask-reactize Purpose Developing a ReactJS application requires to use nodejs as back end server. What if you want to consume external APIs: how are

Julien Chomarat 4 Jan 11, 2022
Full text search for flask.

flask-msearch Installation To install flask-msearch: pip install flask-msearch # when MSEARCH_BACKEND = "whoosh" pip install whoosh blinker # when MSE

honmaple 197 Dec 29, 2022
The Snoopy boilerplate in flask framework for development enterprise application.

Snoopy What is snoopy! The "Snoopy" boilerplate in flask framework for development enterprise application. Motivation In my 10 years of development ex

Bekhzod 2 Sep 29, 2022
Flask-Bcrypt is a Flask extension that provides bcrypt hashing utilities for your application.

Flask-Bcrypt Flask-Bcrypt is a Flask extension that provides bcrypt hashing utilities for your application. Due to the recent increased prevelance of

Max Countryman 310 Dec 14, 2022
Flask-Rebar combines flask, marshmallow, and swagger for robust REST services.

Flask-Rebar Flask-Rebar combines flask, marshmallow, and swagger for robust REST services. Features Request and Response Validation - Flask-Rebar reli

PlanGrid 223 Dec 19, 2022
Flask-Bcrypt is a Flask extension that provides bcrypt hashing utilities for your application.

Flask-Bcrypt Flask-Bcrypt is a Flask extension that provides bcrypt hashing utilities for your application. Due to the recent increased prevelance of

Max Countryman 282 Feb 11, 2021
Brandnew-flask is a CLI tool used to generate a powerful and mordern flask-app that supports the production environment.

Brandnew-flask is still in the initial stage and needs to be updated and improved continuously. Everyone is welcome to maintain and improve this CLI.

brandonye 4 Jul 17, 2022
A Fast API style support for Flask. Gives you MyPy types with the flexibility of flask

Flask-Fastx Flask-Fastx is a Fast API style support for Flask. It Gives you MyPy types with the flexibility of flask. Compatibility Flask-Fastx requir

Tactful.ai 18 Nov 26, 2022
Flask-app scaffold, generate flask restful backend

Flask-app scaffold, generate flask restful backend

jacksmile 1 Nov 24, 2021
Flask pre-setup architecture. This can be used in any flask project for a faster and better project code structure.

Flask pre-setup architecture. This can be used in any flask project for a faster and better project code structure. All the required libraries are already installed easily to use in any big project.

Ajay kumar sharma 5 Jun 14, 2022
Pf-flask-rest-com - Flask REST API Common Implementation by Problem Fighter Library

In the name of God, the Most Gracious, the Most Merciful. PF-Flask-Rest-Com Docu

Problem Fighter 3 Jan 15, 2022
Flask-Discord-Bot-Dashboard - A simple discord Bot dashboard created in Flask Python

Flask-Discord-Bot-Dashboard A simple discord Bot dashboard created in Flask Pyth

Ethan 8 Dec 22, 2022
Open-source Flask Sample built on top of flask-dance library

Open-source Flask Sample built on top of flask-dance library. The project implements the social login for Github and Twitter - Originally coded by TestDriven.IO.

App Generator 4 Jul 26, 2022
Flask-redmail - Email sending for Flask

Flask Red Mail: Email Sending for Flask Flask extension for Red Mail What is it?

Mikael Koli 11 Sep 23, 2022
Flask Sitemapper is a small Python 3 package that generates XML sitemaps for Flask applications.

Flask Sitemapper Flask Sitemapper is a small Python 3 package that generates XML sitemaps for Flask applications. This allows you to create a nice and

null 6 Jan 6, 2023
Flask-template - A simple template for make an flask api

flask-template By GaGoU :3 a simple template for make an flask api notes: you ca

GaGoU 2 Feb 17, 2022