Django RestApis example – GET/POST/PUT/DELETE requests to PostgreSQL database
Django
11
restapi
48
Postgresql
42
Male avatar

loveprogramming viết ngày 10/04/2021

https://grokonez.com/django/django-restapis-postgresql-example-django-rest-framework-tutorial

In this tutorial, we’re gonna look at way to create Django RestAPIs with Get/Post/Put/Delete requests to interact with PostgreSQL Database using Django REST Framework.

Related Post: Django RestApis CRUD Application with Angular 6 & PostgreSQL tutorial

Django RestApi example Overview

Goal

The project create a set of Rest-APIs for GET/POST/UPDATE/DELETE APIs:

  • GET /customers/: get all customers
  • GET /customers/[id]: get a customer by id
  • POST /customers/: save a customer
  • PUT /customers/update/[id]: update a customer by id
  • DELETE /customers/[id]: delete a customer by id

We will config the Project to work with PostgreSQL database.

Project structure

There are several folders and files in our Django project:

django-restapi-postgresql-example-django-rest-framework-tutorial-project-structure

  • customers/apps.py: declares CustomersConfig class (subclass of the django.apps.AppConfig) that represents our Django app and its configuration.
  • gkzRestApi/settings.py: configures settings for the Django project, including INSTALLED_APPS list with Django REST framework and Customers Application.
  • customers/models.py: defines Customer data model class (subclass of the django.db.models.Model).
  • migrations/0001_initial.py: is generated by makemigrations command, includes the code to create the Customer model, will be run by migrate to generate PostgreSQL database table for Customer model.
  • customers/serializers.py: declares CustomerSerializer class (subclass of rest_framework.serializers.ModelSerializer) for Customer instances to manage serialization to JSON and deserialization from JSON.
  • customers/views.py: contains methods to process HTTP requests and produce HTTP responses (using CustomerSerializer).
  • customers/urls.py: defines urlpatterns to be matched with request functions in the views.py.
  • gkzRestApi/urls.py: defines root URL configurations that includes the URL patterns declared in customers/urls.py.

Setup Django RestApi project

More at: https://grokonez.com/django/django-restapis-postgresql-example-django-rest-framework-tutorial

Bình luận


White
{{ comment.user.name }}
Bỏ hay Hay
{{comment.like_count}}
Male avatar
{{ comment_error }}
Hủy
   

Hiển thị thử

Chỉnh sửa

Male avatar

loveprogramming

451 bài viết.
79 người follow
Kipalog
{{userFollowed ? 'Following' : 'Follow'}}
Cùng một tác giả
Male avatar
1 0
Tutorial Link: (Link) (Ảnh) Django is a Pythonbased free and opensource web framework that follows the modeltemplateview architectural pattern. A...
loveprogramming viết 6 tháng trước
1 0
Male avatar
1 0
https://loizenai.com/angular11nodejspostgresqlcrudexample/ Angular 11 Node.js PostgreSQL Crud Example (Ảnh) Tutorial: “Angular 11 Node.js Postg...
loveprogramming viết 5 tháng trước
1 0
Male avatar
1 0
Angular Spring Boot jwt Authentication Example Github https://loizenai.com/angularspringbootjwt/ (Ảnh) Tutorial: ” Angular Spring Boot jwt Authe...
loveprogramming viết 5 tháng trước
1 0
Bài viết liên quan
Male avatar
0 0
https://ozenero.com/djangoangular6exampledjangorestframeworkmysqlcrudexamplepart2djangoserver Django + Angular 6 example | Django Rest Framework +...
loveprogramming viết 5 ngày trước
0 0
{{like_count}}

kipalog

{{ comment_count }}

bình luận

{{liked ? "Đã kipalog" : "Kipalog"}}


Male avatar
{{userFollowed ? 'Following' : 'Follow'}}
451 bài viết.
79 người follow

 Đầu mục bài viết

Vẫn còn nữa! x

Kipalog vẫn còn rất nhiều bài viết hay và chủ đề thú vị chờ bạn khám phá!