A simple library prototype using Python and Flask.
- Create Books
- Search Books
- Delete Books
- Update Books
- Review Books
- Message System
- User Registration & Login
- Account Info & Update
- Create a table for Authors.
- Create the interface for Authors.
git clone https://github.com/the-akira/Flask-Library.git
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/
.
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!