Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/the-akira/flask-library
A simple library prototype using Python and Flask
https://github.com/the-akira/flask-library
cloudinary cloudinary-api flask flask-application flask-backend flask-sqlalchemy flask-wtf heroku-deployment python3
Last synced: 2 months ago
JSON representation
A simple library prototype using Python and Flask
- Host: GitHub
- URL: https://github.com/the-akira/flask-library
- Owner: the-akira
- Created: 2019-09-02T23:26:50.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-21T03:07:06.000Z (11 months ago)
- Last Synced: 2024-02-21T04:25:05.245Z (11 months ago)
- Topics: cloudinary, cloudinary-api, flask, flask-application, flask-backend, flask-sqlalchemy, flask-wtf, heroku-deployment, python3
- Language: HTML
- Homepage: https://secretslibrary.pythonanywhere.com
- Size: 3.7 MB
- Stars: 3
- Watchers: 3
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Flask Library
![img](https://raw.githubusercontent.com/the-akira/Flask-Library/master/projeto/static/img/Avatar.png)
A simple library prototype using [Python](https://www.python.org/) and [Flask](https://flask.palletsprojects.com/en/2.1.x/).
## 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](https://python.land/introduction-to-python/the-repl) in your terminal:
```
python
```Creating a new database:
```python
>>> from projeto import db
>>> db.create_all()
```Initiating a new app context:
```python
>>> from projeto import create_app
>>> app = create_app()
>>> app.app_context().push()
```Importing the database models:
```python
>>> from projeto.models import User, Book, Analysis
```Inserting a new user in the database:
```python
user = User(
username='talantyr',
email='[email protected]',
image_file='default.jpg',
password='22447755'
)
db.session.add(user)
db.session.commit()
```Querying for all users in the database:
```python
>>> users = User.query.all()
>>> [user.email for user in users]
```Search for a user with a specific ID:
```python
>>> User.query.get(1)
```Order users by email ascending:
```python
>>> users = User.query.order_by(User.email.asc())
>>> [user for user in users]
```Search for a specific user in the database:
```python
>>> users = User.query.filter(User.username.contains('aki'))
>>> [user for user in users]
```Add a new book to the database with the current user:
```python
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:
```python
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!