Oldingi loyihalarimda frontendchilar bilan muayyan response formatiga kelishib olib ishlardik. Ya’ni har bir response quyidagicha bo‘lishi kerak edi:
{
"message": "All good",
"status_code": 200,
"data": [{...}]
}
""" | |
$ wget https://hugovk.github.io/top-pypi-packages/top-pypi-packages-30-days.json | |
$ python django-top-100.py | |
""" | |
import json | |
from pathlib import Path |
Enjoy ! 😄
Download iTerm2 here.
services: | |
odoo: | |
image: odoo:17.0 | |
container_name: odoo | |
restart: unless-stopped | |
links: | |
- db:db | |
depends_on: | |
- db |
from functools import lru_cache, wraps | |
from time import monotonic | |
def lru_cache_with_ttl(maxsize=128, typed=False, ttl=60): | |
"""Least-recently used cache with time-to-live (ttl) limit.""" | |
class Result: | |
__slots__ = ("value", "death") |
Mobile = /^9989[012345789][0-9]{7}$/
All = /^998(9[012345789]|6[125679]|7[01234569])[0-9]{7}$/
from pdf_generator import PDFGenerator | |
instance = Model.objacts.get(id=1) #example | |
context = { | |
"data": instance | |
} #use as {{ data }} in html_file_path | |
#Create object | |
pdf = PDFGenerator( |
from openpyxl import Workbook | |
from django.http import HttpResponse | |
from datetime import datetime, date | |
from .export_excel import ExportExcelAction | |
from openpyxl.styles import Font | |
from unidecode import unidecode | |
def style_output_file(file): | |
black_font = Font(color='000000', bold=True) |
Impactt co-working markazi rezidentlariga majlis xonalarni oldindan oson band qilish uchun tizim yaratmoqchi va bunda sizning yordamingiz kerak.
Backend yo'nalishiga topshirganlar tizim uchun REST API tuzishi kerak bo'ladi. Frontend yo'nalishi qatnashchilaridan esa ushbu tizim uchun foydalanuvchi interfeysini yasash kutiladi.
__str__
va __repr__
bular classning metodi bo'lib, biz bularni yozilgan kodlarni so'ngida, qayta tekshirish maqsadida, ya'ni debugging qilishga foydalanamiz.
__repr__
bu maxsus string taqdim etuvchini obyektlarni qaytaradigan metod hisoblanadi.
__str__
esa, maxsus bo'lmagan string qatnashgan obyektlarni qaytaruvchi metod hisoblanadi. __str__
ni taqdim qilish str()
built-in funksiyasini e'lon qilish orqali amalga oshiriladi, __repr__
ni taqdim qilish uchun ham, huddi shunday repr()
funksiyasi orqli amalga oshiriladi.