2. Pagination siz:
3. Error response holati:
* bu yerda keltirilgan structura misol uchun, aslida o'zingiz hohlaganday qilishingiz mumkin.
response = CustomResponse.success(
message="Data retrieved successfully",
data={"key": "value"}
)
3. Error response holati:
response = CustomResponse.error(
message="Invalid input provided",
status_code=400
)
return CustomResponse.error(message=_("Folder not found"), status_code=404)
👍3🔥3
Forwarded from Sirojiddin Yokubov |IT| Channel
🔌 WSGI — Web Server Gateway Interface nima va u qanday ishlaydi?
WSGI — bu Python ilovasi va web server o‘rtasidagi interfeys. U Python ilovalarini mustaqil web serverlar bilan ulash uchun yaratilgan standart (PEP 3333).
🧐 Nega WSGI kerak?
Python’ning o‘zi HTTP so‘rovlarni to‘g‘ridan-to‘g‘ri qabul qila olmaydi. Web serverlar esa so‘rovlarni olish, load balancing, static fayllarni berish kabi ishlarni bajaradi.
Ammo ular Python kodini to‘g‘ridan-to‘g‘ri ishlata olmaydi. WSGI bu ikkisini bog‘lovchi ko‘prik vazifasini bajaradi.
📥 So‘rovdan Javobgacha qanday oqim bo‘ladi?
1. Foydalanuvchi brauzer orqali HTTP so‘rov yuboradi.
2. Web server (masalan, Nginx yoki Apache) bu so‘rovni oladi.
3. U so‘rovni Gunicorn yoki uWSGI kabi WSGI serveriga uzatadi.
4. WSGI server
5. Ilova
6. Natija web server orqali foydalanuvchiga yuboriladi.
🔧 WSGI nimani yengillashtiradi?
- Ilova va serverni mustaqil qiladi: istalgan Python framework (Django, Flask) istalgan serverda (Gunicorn, uWSGI) ishlaydi.
- Performance va scalability uchun optimallashtirishni web serverga topshiradi.
- Bu standart bo‘lishi tufayli, loyihalar orasida moslashuvchanlikni oshiradi.
🔍 Muqobil variantlar bormi?
Ha. ASGI — WSGI ning asynchronous versiyasi bo‘lib, real-time (chat, WebSocket) ilovalar uchun ishlatiladi. Ammo, oddiy HTTP ilovalar uchun WSGI hali ham keng qo‘llaniladi.
📚 Manbalar:
- https://builtin.com/data-science/wsgi
- https://peps.python.org/pep-3333/
👉 Bizni kuzatishda davom eting keyingi postimizda ASGI haqida gaplashamiz: @yakubovdeveloper
WSGI — bu Python ilovasi va web server o‘rtasidagi interfeys. U Python ilovalarini mustaqil web serverlar bilan ulash uchun yaratilgan standart (PEP 3333).
🧐 Nega WSGI kerak?
Python’ning o‘zi HTTP so‘rovlarni to‘g‘ridan-to‘g‘ri qabul qila olmaydi. Web serverlar esa so‘rovlarni olish, load balancing, static fayllarni berish kabi ishlarni bajaradi.
Ammo ular Python kodini to‘g‘ridan-to‘g‘ri ishlata olmaydi. WSGI bu ikkisini bog‘lovchi ko‘prik vazifasini bajaradi.
📥 So‘rovdan Javobgacha qanday oqim bo‘ladi?
1. Foydalanuvchi brauzer orqali HTTP so‘rov yuboradi.
2. Web server (masalan, Nginx yoki Apache) bu so‘rovni oladi.
3. U so‘rovni Gunicorn yoki uWSGI kabi WSGI serveriga uzatadi.
4. WSGI server
application(environ, start_response)
funksiyasini chaqiradi. 5. Ilova
start_response()
orqali status va header qaytaradi va natijani iterable sifatida jo‘natadi. 6. Natija web server orqali foydalanuvchiga yuboriladi.
🔧 WSGI nimani yengillashtiradi?
- Ilova va serverni mustaqil qiladi: istalgan Python framework (Django, Flask) istalgan serverda (Gunicorn, uWSGI) ishlaydi.
- Performance va scalability uchun optimallashtirishni web serverga topshiradi.
- Bu standart bo‘lishi tufayli, loyihalar orasida moslashuvchanlikni oshiradi.
🔍 Muqobil variantlar bormi?
Ha. ASGI — WSGI ning asynchronous versiyasi bo‘lib, real-time (chat, WebSocket) ilovalar uchun ishlatiladi. Ammo, oddiy HTTP ilovalar uchun WSGI hali ham keng qo‘llaniladi.
📚 Manbalar:
- https://builtin.com/data-science/wsgi
- https://peps.python.org/pep-3333/
👉 Bizni kuzatishda davom eting keyingi postimizda ASGI haqida gaplashamiz: @yakubovdeveloper
Python Enhancement Proposals (PEPs)
PEP 3333 – Python Web Server Gateway Interface v1.0.1 | peps.python.org
This document specifies a proposed standard interface between web servers and Python web applications or frameworks, to promote web application portability across a variety of web servers.
⚡9👍8
Django da ko'p qilinadigan xatolar #1
Model save() metodida quyidagi holatni ko'p ishlatish
yaxshidek ko'rinadi ammo unday emas, agar kodda kimdur bulk_create() ishlatgan holda 10k user yaratgan bo'lsa 10k email yuborlmay qoladi🫠
shuning uchun bunaqa ishlarni odatda signals da yoki user save qilayotgan joyda task orqali hal qilish yaxshi yechim 👌
Model save() metodida quyidagi holatni ko'p ishlatish
class User(models.Model):
def save(self, *args, **kwargs):
if not self.pk:
send_welcome_email(self.email)
super().save(*args, **kwargs)
yaxshidek ko'rinadi ammo unday emas, agar kodda kimdur bulk_create() ishlatgan holda 10k user yaratgan bo'lsa 10k email yuborlmay qoladi🫠
shuning uchun bunaqa ishlarni odatda signals da yoki user save qilayotgan joyda task orqali hal qilish yaxshi yechim 👌
🫡5❤1
https://medium.com/@pesarakex/how-i-reduced-a-3gb-django-table-query-from-12s-to-200ms-with-just-3-indexes-eec82e99cec9
Django model:
Django model:
class Record(models.Model):
user = models.ForeignKey('auth.User', on_delete=models.CASCADE)
status = models.CharField(max_length=50)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
indexes = [
models.Index(fields=['user', 'status'], name='idx_record_user_status'),
models.Index(fields=['-created_at'], name='idx_record_created_at'),
models.Index(fields=['user', 'status', '-created_at'], name='idx_record_user_status_created'),
]
Lesson?
You don’t need 17 microservices when you can write clean Django apps with clear domain boundaries. Monoliths scale just fine if you don’t treat them like spaghetti.
Link to the article
You don’t need 17 microservices when you can write clean Django apps with clear domain boundaries. Monoliths scale just fine if you don’t treat them like spaghetti.
Link to the article
Medium
How Disqus Scaled to Billions of Requests Using Django (Yes, Django!)
Everyone says Django can’t scale. Disqus proved otherwise—and they did it without going full microservices or rewriting everything in Go.
👍1
Pythonda katta hajmdagi tashqi API so'rovlarini qanday qilib qisqa vaqt ichida samarali amalga oshirish mumkin deb yurganlar uchun bir nechta maqolalar bilan bo'lishaman.
1. Yes, Python Scales: Lessons from Handling Millions of API Calls a Day
2. Efficient Techniques for Sending 100,000 HTTP Requests
3. Efficient Methods for Sending 100k Requests
1. Yes, Python Scales: Lessons from Handling Millions of API Calls a Day
2. Efficient Techniques for Sending 100,000 HTTP Requests
3. Efficient Methods for Sending 100k Requests
Medium
Yes, Python Scales: Lessons from Handling Millions of API Calls a Day
Python can absolutely scale. Four low‑effort tweaks gave us 60‑90% speed‑ups in the real‑world snippets below