Best Flask open-source libraries and packages

Flask Library

A simple library prototype using Python and Flask
Updated 11 months ago

Flask Library

img

A simple library prototype using Python and Flask.

Features

  • Create Books
  • Search Books
  • Delete Books
  • Update Books
  • Review Books
  • Message System
  • User Registration & Login
  • Account Info & Update

TODO

  • Create a table for Authors.
  • Create the interface for Authors.

Installation

Clone the Repository

git clone https://github.com/the-akira/Flask-Library.git

Inside the Main Directory

Create a Virtual Environment:

python -m venv myvenv

Activate the Virtual Environment:

source myvenv/bin/activate

Install Requirements:

pip install -r requirements.txt

Run the Application:

python run.py

Open your Web Browser and navigate to http://127.0.0.1:5000/.

Managing the Database

Inside the Main Directory

Start a new Python REPL in your terminal:

python

Creating a new database:

>>> from projeto import db
>>> db.create_all()

Initiating a new app context:

>>> from projeto import create_app
>>> app = create_app()
>>> app.app_context().push()

Importing the database models:

>>> from projeto.models import User, Book, Analysis

Inserting a new user in the database:

user = User(
    username='talantyr', 
    email='talantyr@gmail.com', 
    image_file='default.jpg', 
    password='22447755'
)
db.session.add(user)
db.session.commit()

Querying for all users in the database:

>>> users = User.query.all()
>>> [user.email for user in users]

Search for a user with a specific ID:

>>> User.query.get(1)

Order users by email ascending:

>>> users = User.query.order_by(User.email.asc())
>>> [user for user in users]

Search for a specific user in the database:

>>> users = User.query.filter(User.username.contains('aki'))
>>> [user for user in users]

Add a new book to the database with the current user:

book = Book(
    title='Quincas Borba', 
    author='Machado de Assis', 
    genre='História', 
    summary='Clássico Brasileiro', 
    user=user
)
db.session.add(book)
db.session.commit()

Create a review for the book:

review = Analysis(
    rating='Muito bom!', 
    review='Um livro altamente incrível', 
    book_id=book.id, 
    user=user
)
db.session.add(review)
db.session.commit()

Have a good read!