A sample project blog project for implemeting flask Restful and sqlalchemy using sqlite as database server
Create a virtual environment(venv) in your project directory using the command
virtualenv venv
if virtual environment is not installed in your system, install virtual env using the command
pip3 install virtualenv
and then create a virtual env for your project
activate the virtual environment, using command
source venv/bin/activate
Install all the requirements mentioned in requirments.txt file using command
pip install -r requirments.txt
incase you are using python3 use the command:
pip3 install -r requirements.txt
open terminal and move to your project directory, use the following command to create models in your database
from app import db
db.create_all()
exit()
check if the models are created or not using the following command
sqlite3 database_name
.tables
example
neha@neha-Latitude-3400:~/Documents/moru_flask_restful_sqlalchemy$ sqlite3 blog.db
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
sqlite> .tables
blog_model
to run the project, use command
python file_name
example
(venv) neha@neha-Latitude-3400:~/Documents/moru_flask_restful_sqlalchemy$ python app.py
to create a blog
url: {{url}}/blogs
body:
{
"text":"sample blog",
"views":20,
"likes":30
}
Method: POST
to get all blogs
url: {{url}}/blogs
Method: GET
to get an individual blog
url: {{url}}/blogs/{{blog_id}}
Method: GET
to update a blog
url: {{url}}/blogs/{{blog_id}}
body:
{
"text":"sample blog",
"views":20,
"likes":30
}
Method: PUT
to delete a blog
url: {{url}}/blogs/{{blog_id}}
Method: DELETE