Django and DRF
302 subscribers
98 photos
39 files
161 links
Purpose is sharing, spreading knowledge which is most related to the Django and Django Rest Framework(DRF)

You can find in here my
- Articles
- Projects with source codes
- Videos
and another useful stuffs
Download Telegram
2
In some cases django devs have one problem with migrations files, so i think the guy who is first met with this issue is gonna delete all of migrations and data in DB. if he does this in the production he will might lost all real data 😰🥴🥶.
Ok WHAT SHOULD IT DO ???
Django has — fake flag which is written with migrate command together like this: python manage.py migrate —fake
It tells to Django that migrations have already applied and not need to run it(DON'T RUN IT).
Actually it creates a row in django_migrations table but not run in the SQL to change table structure.
In one another case if you have multiple migrations file you can delete all of them and use above flag(argument).
Improving API Performance
More
👍3
🔥 I absolutely recommended reading this article to learn more about object serializing way and you realize that which way is the best to serialize in short time.

https://hakibenita.com/django-rest-framework-slow
Architectures
More
Nima uchun Django loyihani serverga joylayotganimizda gunicorn servisidan foydalanamiz ?, Django runserver dan foydalanish mumkinku !?

Bu yangi dasturchilar orasida juda ko'p so'ralgan savol

Bu yerda mening tushuncham:👇

⛔️ Djangoning runserveri Single-Thread:

Ko'p qatorli avtomagistraldan farqli o'laroq, runserver - bu bitta qatorli yo'l ga o'xshaydi. U bir vaqtning o'zida faqat birgina so'rovni tutib(handle) qolishi mumkin, bir vaqtning o'zida bir nechta so'rovlar kelganda navbatlarning paydo bo'lishiga olib keladi. Bu userlar yuqori trafik ostida qolib, javob olish vaqtlari sekinlashishiga olib keladi.

Enter Gunicorn: The Concurrency Hero 💪

Gunicorn production muhitida:

Concurrent Processing: Gunicorn ishchi processlarini yaratadi, har biri mini-django app sifatida ishlaydi. So'rovlar yetib kelgan vaqtda, Gunicorn ishchilarni(workers) bo'lib tashlaydi, processlarga parallel ravishda ishlashga imkon beradi. Va bu sezilari darajada performance ni oshishiga tasir qiladi, ayniqsa og'ir trafik ostidagilar uchun.

Scalability: Gunicorn da trafik talablaringizga mos worker processlarning sonini sozlab quyish mumkin.Bu avtomagistrallarga eng tirband bo'lgan vaqtda qo'shimcha yo'llar qo'shishga o'xshaydi

Production-Ready Features: Gunicorn real loyihalarning deployment jarayoni uchun muhim hususiyatlarni taqdim qiladi, ya'ni quyidahilar:

🔹 Pre-forking - so'rovlarni samarali handle qilish uchun worker proccesslarni qayta ishlatish.

🔹 Ilovani restart qilmasdan uning code larni muammosiz o'zgartirish uchun juda zo'r Reloading.

🔹 Timeouts va workerlarni samarali monitoring qilish scaling uchun.

🔹 Yuqori darajadagi loggin va errorlarni handle qilish kuzatishni yaxshilash uchun.

Gunicorndan foydalangan holatda, siz Django loyihangizni samarali scale qila olasiz, so'rovlarni parallel ravishda handle qilish, va foydalanuvchiga muammosiz yetkazib berish – hatto yuqori o'lchamdagi traffic bo'lgan taqdirda ham.
🔥8
#savol
Access tokenni yaroqlilik muddatini 2 3 yil qilsam ham boladimi. 😢

javob:
haa bo'ladi, lekin bu holatda havfsizlikni o'ylamasangiz ham bo'ladi chunki agar hujum qilishmoqchi bo'lsa 1 2 kunda dasturizni qo'lga olishi mumkin. token dan foydalanmasangiz ham bo'ladi😁 agar 2 3 yil qilmoqchi bo'lsangiz chunki foydasi tegmaydi baribir.
Backend dasturchi bilishi kerak bo'lgan eng muhim 'qobiliyat' nima deb o'ylaysiz ?

Javoblarni komentariyada qoldiring, men uzimnikini kun yakunida qoldiraman.
👍2
Django and DRF
Backend dasturchi bilishi kerak bo'lgan eng muhim 'qobiliyat' nima deb o'ylaysiz ? Javoblarni komentariyada qoldiring, men uzimnikini kun yakunida qoldiraman.
Men uchun eng muhim part bu Database Structurasi ya'ni uni qurish, Design qilish.

Chunki bu qismni skip qilib ketish oqibatida kelajakda ko'p disadvantage tomonlarini kurishimiz mumkin.

1. Kod Trash ga aylanishi aniq I think so.

2. Ma'lumotlarni optimal tarzda database ga saqlash, olish, o'chirish, yangilash(CRUD) ni tezligini bir necha barobarga oshiradi.

3. Ortiqcha keraksiz querylarni yozishdan qutilish.

Design Tayyor boo'lgandan so'ng Mazza qilib api chiqarishga o'tsez bo'ladi 😂

Tepada yangi boshlayotgan loyihamizni Database Design ni, bugungi qilgan ishim shu bo'ldi🤓

Kamchiliklar bo'lsa yoki qo'shimcha qo'shmoqchi bo'lsangiz komentariyada fikringizni qoldiring 👇🏻
👍2
How to add multiple database in Django framework.pdf
7.9 MB
Bitta Django Loyihada qanday qilib bir nechta Database lardan foydalanish mumkin ?

#edited
pre-commit larni ishlatgan holda kodizni bir nechta Tekshiruvlardan o'tkazib toza 🧹, missed xatoliklardan fix qilib 🥺, refactoring qilish 🥶 va black,flake8,isort larni ishlatib vanihoyat yaratilmagan migratsiyalar qolib ketgan bo'lsa😢 ularni ham tekshirib Testlardan🧪 o'tkazib, coverage ni ham aniqlab ko'rgandan so'ng commit bo'lganini ko'rsangiz mazza qivorasiz 😎, ishonavering 😁

pre-commit haqida nimalar bilasiz, batafsil post qilishimni hohlaysizmi ?

leave your thoughts in the comments 👇🏻
👍6👌2
Django Rest Framework orqali API lar chiqarganimizda ularni frontend dasturchilarga tushunarli tarzda yetkazishimiz uchun Dokumentatsiya yozishimiz kerak bo'ladi.

Shu documentatsiyani yozish uchun DRF da 2 ta popular packagelar bor drf-spectacular va drf-yasg,
Savol: Ikkalasini kotta farqi nimada ?, qanday advantage, disadvantage lari bor ?
👍2
𝐖𝐡𝐚𝐭 𝐢𝐬 𝐂𝐨𝐧𝐭𝐞𝐧𝐭 𝐃𝐞𝐥𝐢𝐯𝐞𝐫𝐲 𝐍𝐞𝐭𝐰𝐨𝐫𝐤 (𝐂𝐃𝐍)?

A CDN is a distributed network of servers strategically located across various geographical locations to deliver web content, such as images, videos, and other static assets, more efficiently to users.

The primary purpose of a CDN is to reduce latency and improve the overall performance of web applications by serving content from the server nearest to the user. CDNs can also help improve reliability, availability, and security of web applications.

𝐁𝐞𝐧𝐞𝐟𝐢𝐭𝐬 𝐨𝐟 𝐮𝐬𝐢𝐧𝐠 𝐚 𝐂𝐃𝐍
CDNs play a crucial role in enhancing the performance, reliability, and security of modern web applications. Here are the top benefits of using CDNs:

🔹1. Reduced latency: By serving content from geographically distributed edge servers, CDNs reduce the time it takes for content to travel from the server to the user, resulting in faster page load times and improved user experience.

🔹2. Improved performance: CDNs can offload static content delivery from the origin server, freeing up resources for dynamic content generation and reducing server load. This can lead to improved overall performance for web applications.

🔹3. Enhanced reliability and availability: With multiple edge servers in different locations, CDNs can provide built-in redundancy and fault tolerance. If one server becomes unavailable, requests can be automatically rerouted to another server, ensuring continuous content delivery.

🔹4. Scalability: CDNs can handle sudden traffic spikes and large volumes of concurrent requests, making it easier to scale web applications to handle growing traffic demands.

🔹5. Security: Many CDNs offer additional security features, such as DDoS protection, Web Application Firewalls (WAF), and SSL/TLS termination at the edge, helping to safeguard web applications from various security threats.

Reference: Introduction to CDN: https://lnkd.in/gwygXpcR

CDN haqida yana qanday +, - larini bilasiz ?
👍2
Django loyihasiga ElasticSearch implementatsiya qilmoqchi bo'lganlar uchun
1. https://django-elasticsearch-dsl-drf.readthedocs.io
2. https://django-elasticsearch-dsl.readthedocs.io/en/latest/

ElasticSearch - bu qidiruv tizmi uchun eng optimal variantlardan biri va loyihangizda live-search ni qullamoqchi bo'lsangiz juda qo'l keladi.

o'rganish uchun:
1. https://testdriven.io/blog/django-drf-elasticsearch/
2. https://www.udemy.com/course/elasticsearch-complete-guide/

bu haqida batafsil post qilaman.
2👌2
Django Optimization
1. Use Advanced Expressions (Q, F, When, Case, ..)
2. Use django debug-toolbar to analyze and optimize each api or function
3. Caching data for not getting again
4. Use annotate(), aggregate() functions
5. Implement select_related(), prefetch_related() instead of increasing query's count
6. Use count() not len()
7. Avoid retrieving data which you don't need: use values_list(), values()
8. Use bulk_create() to create multiple entries
9. Use foreignkey values directly: book.user.id , book.user_id
10. Use Celery to do tasks using queues
....
qolganini commentda davom ettirishingiz mumkin 😊

Optimization haqidagi videolar to'plami: https://youtube.com/playlist?list=PLmSbOYZOHCRoNruZA0prIvOVu2mv3JzFm&feature=shared
🔥5👍1
Backend Expert Guide.pdf
6.9 MB
Helpful Interview questions for Backend developers.
👍4
Django dagi mavjud signallar

request_started - bu signal HTTP request proccesing eng boshlangich qismida ishlaydi, ya'ni Views, Middlewares dan ham oldin.

Yasalishi:
from django.core.signals import request_started
from django.dispatch import receiver

@receiver(request_started)
def my_callback(sender, **kwargs):
print("Request started!")


Foydalanish uchun caselar:
1. Logging
2. Performance Monitoring

more
👍51