TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #397 · 12 ное.

Использование Pydantic сегодня стало нормой, и это правильно. Но иногда на ревью вижу, что используют его не всегда корректно. Например, метод BaseModel.model_dump() по умолчанию не преобразует стандартные типы, такие как datetime, UUID или Decimal, в простой сериализуемый для JSON вид. Тогда пишут кастмоный сериализатор для этих типов чтобы функция json.dump() не падала с ошибкой. import uuid from datetime import datetime from decimal import Decimal from uuid import UUID from pydantic import BaseModel class MyModel(BaseModel): id: UUID date: datetime value: Decimal obj = MyModel( id=uuid.uuid4(), date=datetime.now(), value='1.23' ) print(obj.model_dump()) # не подходит для json.dump # { # 'id': UUID('4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1'), # 'date': datetime.datetime(2025, 12, 12, 12, 12, 12, 111111), # 'value': Decimal('1.23') # } # добавляем свой кастомный сериализатор json.dumps(obj.model_dump(), cls=MySerializer) # { # 'id': '4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1', # 'date': '2025-12-12T12:12:12.111111', # 'value': '1.23' # } В данном случае класс MySerializer обрабатывает datetime, UUID и Decimal. Например так: class MySerializer(json.JSONEncoder): def default(self, o): if isinstance(o, Decimal): return str(o) elif isinstance(o, datetime): return o.isoformat() elif isinstance(o, UUID): return str(o) return super().default(o) Специально для тех, кто всё еще так делает - в этом нет необходимости! Pydantic может это сделать сам, просто нужно добавить параметр mode="json". json.dumps(obj.model_dump(mode="json")) # { # 'id': '4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1', # 'date': '2012-12-12T12:12:12.111111', # 'value': '1.23' # } #pydantic#libs

Резултати

Пронајдени 5 слични објави

Пребарај: #heroku

当前筛选 #heroku清除筛选
ALL About RSS

@AboutRss · Post #945 · 26.01.2021 г., 01:00

一键在 #Heroku 上部署 #RSS阅读器 Miniflux 接推友 sayo melu 投稿: https://twitter.com/sayomelu/status/1352981374861361154 Ta 分享了自己的 Repo 「heroku-miniflux」 ,实现不花钱地拥有一个 #Miniflux : https://github.com/sayomelu/heroku-miniflux 本推送的评论回复部分有一些需要注意的 tips 。

djangoproject

@djangoproject · Post #122 · 25.08.2016 г., 04:45

https://github.com/python-telegram-bot/python-telegram-bot/wiki/Webhooks#heroku On #Heroku using #webhook can be beneficial on the free-plan because it will automatically manage the downtime required. The reverse proxy is set up for you and an environment is created. From this environment you will have to extract the port the #bot is supposed to listen on. Heroku manages the #SSL on the #proxy side, so you don't have provide the certificate yourself.

Indian Bots

@indianbots · Post #449 · 24.11.2021 г., 13:51

Build A screen recorder with python #pythonprogramming#obs#heroku#heroku#infotel follow me in github - www.github.com/rohith-sreedharan follow me on Instagram - Instagram.com/rohithaditya_2004 follow me on Twitter - Twitter.com/rohithaditya follow our bot channel - telegram.me/Bots_universe website - botsuniverse.live mail - [email protected]

Dasturlash hayoti️️ ️

@dasturlash_hayoti · Post #3714 · 16.03.2025 г., 14:18

#hosting#netlify#webhost#heroku Qanday qilib yaratgan saytingizni internetga bepul joylash mumkin? 🔗netlify.com 🔗000webhost.com 🔗heroku.com Mana shu saytlar orqali siz saytingizni bepul internetga qo'ysangiz bo'ladi 😉 💻@dasturlash_hayoti — bir xatoni tuzatib, ikkinchisiga tayyorlanish! 😅

Dasturlash hayoti️️ ️

@dasturlash_hayoti · Post #3112 · 08.03.2024 г., 08:07

#hosting#netlify#webhost#heroku Qanday qilib yaratgan saytingizni internetga bepul joylash mumkin? 🔗netlify.com 🔗000webhost.com 🔗heroku.com Mana shu saytlar orqali siz saytingizni bepul internetga qo'ysangiz bo'ladi 😉 💻@dasturlash_hayoti — dasturchilar va dasturlash hayotini yoritib boradigan loyiha!