Python-Django-Rest framework API

Python-Django-Rest framework API

Python-Django-Rest framework API

Birinchi navbatda Django’i Django-rest-framework o’rnatamiz.

#Linux:

sudo pip3 install Django

sudo pip3 install django-rest-framework

#Windows:

pip install Django

pip install django-rest-framework

Modullarni o’rnatib bo’ldi. Endi cmd yoki linux terminalini ochib, quyidagi buyruqni yozamiz:

django-admin startproject myapi

python django rest framework api 65e6117ea8fef

Mana shunday papka ochilishi kerak

Endi

cd myapi

qilib papkani ichiga o’tib olamiz.

Keyin

python manage.py startapp API

buyrug’ini beramiz.

python django rest framework api 65e6117fb332e

API digan papka yaratilgan bo’lishi kerak. Endi settings.py faylini ochamiz.

python django rest framework api 65e61180c05bd

Bu yerga startapp’dagi faylimiz nomini kiratamiz: «API» endi urls.py ga kiramiz

Har qanday get yoki post kelgan so’rovlarni API degan papkaga boradi

python django rest framework api 65e61181e4914

Endi AP degan papkamiz ichidan urls.py degan fayl ochamiz va models.py’ga kirib, u yerdan database qilib olamiz.

python django rest framework api 65e61183104ec

Endi terminalga quyidagi buyruqni yozamiz:

python manage.py makemigrations

python manage.py migrate

python django rest framework api 65e6118e26192

mana bo’ldi, database tayyor. Endi admin.py’ga kiramiz:

python django rest framework api 65e6118f3b4cf

Mana databasni admin paneliga qo’shib oldik. Endi runserver qilib ko’ramiz:

python manage.py runserver

python django rest framework api 65e6119059ac2

Brauzerdan http://127.0.0.1:8000/admin havolasiga kiramiz

Kiramiz-u, afsuski, login-parolni unutamiz 😁😁😁

Terminalga kirib ctrl+c’ni bosamiz.

python django rest framework api 65e6119176a61

Mana admin sifatida ro’yxatdan o’tib oldik. Endi yana quyidagi buyruqni beramiz:

python manage.py runserver

Va http://127.0.0.1:8000/admin shu havolaga kiramiz.

python django rest framework api 65e611929b3d3

Login-parol teramiz

python django rest framework api 65e61193781d2

Sizlarda ham huddi shunday chiqishi kerak. Endi product’ga kiramiz va productlar qoshamiz.

python django rest framework api 65e611946b5cf

Huddi shunday qilib 10-15 marta product qo’shamiz.

Va ana endi views.py faylga kiramiz, oldin serverni o’chiramiz. Buning uchun terminalga kirib, ctrl+c’ni bosamiz.

python django rest framework api 65e61195547f4

Hammasi rasm bo’yicha qilamiz. Iltimos, diqqat bilan e’tibor bering!

python django rest framework api 65e611967c19b

python django rest framework api 65e61197a0086

serializers.py nomli fayl yaratamiz

python django rest framework api 65e61198c0671

python django rest framework api 65e61199dbb5e
python django rest framework api 65e6119b07b4d

python django rest framework api 65e6119c219f5

Va nihoyat tugadi. Ha bu boshida qiyin ko’rinadi va buni so’z bilan tushuntirish qiyin. Lekin 1 yoki 2 oyda yaxshi o’rganib olishingiz mumkin. Xatolar bo’lsa oldindan uzr so’rayman 😊😊😊 Savollaringiz bo’lsa qoldiring. Iltimos diqqat bilan rasmlarga qarang!!! Qo’limdan kelganicha tushuntirishga hakarat qildim.

API
Python-Django-Rest framework API