This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io | |
| from rest_framework.parsers import JSONParser | |
| stream = io.BytesIO(json) | |
| data = JSONParser().parse(stream) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| serializer = CommentSerializer(data=data) | |
| serializer.is_valid() | |
| # True | |
| serializer.validated_data | |
| # {'content': 'My content', 'email': 'djwoms@example.com', 'created': datetime.datetime(2022, 09, 06, 16, 20, 09, 822243)} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sqlalchemy import create_engine | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from sqlalchemy.orm import sessionmaker | |
| DATABASE_NAME = 'track_db.sqlite' | |
| engine = create_engine(f'sqlite:///{DATABASE_NAME}') | |
| Session = sessionmaker(bind=engine) | |
| Base = declarative_base() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:io'; | |
| import 'package:http/http.dart' as http; | |
| void main() async { | |
| checkSite('https://www.google.com'); | |
| checkSite('https://www.nonexistentsite.com'); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import datetime as dt | |
| class Record: | |
| # Лучше использовать date=None вместо date=''. | |
| # None явно означает "не передано", пустая строка это конкретное значение. | |
| # Ниже проверка `not date` сработает одинаково для '' и None, | |
| # но с None код читается понятнее. | |
| def __init__(self, amount, comment, date=None): | |
| self.amount = amount |
OlderNewer