https://github.com/mhmzdev/django-restframework-learning
Repo that contains beginner's friendly examples and basics of django-restframework to get started
https://github.com/mhmzdev/django-restframework-learning
Last synced: about 1 year ago
JSON representation
Repo that contains beginner's friendly examples and basics of django-restframework to get started
- Host: GitHub
- URL: https://github.com/mhmzdev/django-restframework-learning
- Owner: mhmzdev
- Created: 2022-08-13T15:48:12.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-18T07:55:45.000Z (over 3 years ago)
- Last Synced: 2025-02-09T23:27:40.025Z (about 1 year ago)
- Language: Python
- Size: 26.4 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Django-restframework learning
I've put all the files in sequence in the branches while I'm learning to use django as backend framework.
### 1st - Creating Django project
- Created django project using command `django-admin startproject learning`
### 2nd - First API view/response
- Created first api view, or we also call it api response
- Create app name `api` via command `python manage.py startapp api`
- return json response from url `http://localhost:8000/home/`
### 3rd - Returning back Data
- Sending Json data from client side to server and handling it.
- More like we send `body` in a `POST` request or `QueryParams`
- Adding data like `headers` and `content_type`
### 4th - Django Model as API response
- Create a separate app `products`
- Make a model/object class in `models.py`
- Migrate the models for DB
This will actually let's the django knows there's a new model to look for now:
- `python manage.py makemigration`
- `python manage.py migrate`
### 5th - Converting Model instance to python dict
- import `model_to_dict`
### 6th - Converting api view to djangon rest framework view
- Used `@api_view()` for DRF
- Stuff like restricting methods `GET`, `POST` etc.