Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lintangwisesa/crud_flask_postgresql
Basic CRUD with Python Flask & PostgreSQL Database
https://github.com/lintangwisesa/crud_flask_postgresql
flask postgresql python
Last synced: 4 days ago
JSON representation
Basic CRUD with Python Flask & PostgreSQL Database
- Host: GitHub
- URL: https://github.com/lintangwisesa/crud_flask_postgresql
- Owner: LintangWisesa
- Created: 2019-01-04T04:11:28.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-10-20T02:40:57.000Z (about 4 years ago)
- Last Synced: 2023-03-07T10:26:53.511Z (over 1 year ago)
- Topics: flask, postgresql, python
- Language: Python
- Size: 6.84 KB
- Stars: 15
- Watchers: 2
- Forks: 16
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![simplinnovation](https://4.bp.blogspot.com/-f7YxPyqHAzY/WJ6VnkvE0SI/AAAAAAAADTQ/0tDQPTrVrtMAFT-q-1-3ktUQT5Il9FGdQCLcB/s350/simpLINnovation1a.png)
# Basic CRUD: Flask & PostgreSQL
1. Activate __PostgreSQL__ server:
```bash
$ cd C:\Program Files\PostgreSQL\10\bin
$ psql -U postgres
Password for user postgres:
```#
2. Create a database on PostgreSQL, my database name is __"lin_flask"__:
```bash
postgres=# CREATE DATABASE lin_flask;
postgres=# \l
postgres=# \c lin_flask
```#
3. Create a __"users"__ table on __"lin_flask"__ database:
```bash
lin_flask=# CREATE TABLE users(
id SERIAL PRIMARY KEY,
name VARCHAR(255),
age VARCAR(255)
);
lin_flask=# \d
```#
4. Clone this repo. Insert your database URI to __database.yaml__ file, then install all the packages needed. In this project I'm using __flask__, __flask_cors__, __flask_mysqldb__, __Flask-SQLAlchemy__ & __psycopg2__:
```bash
$ git clone https://github.com/LintangWisesa/CRUD_Flask_PostgreSQL.git
$ cd CRUD_Flask_PostgreSQL
$ pip install flask flask_cors Flask-SQLAlchemy psycopg2
```#
5. Run the server file. Make sure your PostgreSQL server is still running. Your application server will run locally at __*http://localhost:5000/*__ :
```bash
$ python app.py
```#
6. Give a request to the server. You can use __Postman__ app:
__See the opening screen (*home.html*)__
```bash
GET /
```__Post a data to database:__
```bash
POST /data
body request: {name:"x", age:"y"}
```
__Get all data & specific data by id:__
```bash
GET /data
GET /data/{:id}
```
__Update a data by id__:
```bash
PUT /data/{:id}
body request: {name:"x", age:"y"}
```
__Delete a data by id:__
```bash
DELETE /data/{:id}
```#
7. Enjoy your code! 😎👌
## See also:
- [Basic CRUD: Flask & MySQL](https://github.com/LintangWisesa/CRUD_Flask_MySQL)
- [Basic CRUD: Flask & PostgreSQL](https://github.com/LintangWisesa/CRUD_Flask_PostgreSQL)
- [Basic CRUD: Flask & MongoDB](https://github.com/LintangWisesa/CRUD_Flask_MongoDB)#
#### Lintang Wisesa :love_letter: [email protected]_
[Facebook](https://www.facebook.com/lintangbagus) |
[Twitter](https://twitter.com/Lintang_Wisesa) |
[Google+](https://plus.google.com/u/0/+LintangWisesa1) |
[Youtube](https://www.youtube.com/user/lintangbagus) |
:octocat: [GitHub](https://github.com/LintangWisesa) |
[Hackster](https://www.hackster.io/lintangwisesa)