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
| 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
| serializer = CommentSerializer(data=data) | |
| serializer.is_valid() | |
| # True | |
| serializer.validated_data | |
| # {'content': 'My content', 'email': '[email protected]', '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
| 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
| from rest_framework.renderers import JSONRenderer | |
| json = JSONRenderer().render(serializer.data) | |
| print(json) | |
| # '{"email": "[email protected]", "content": "foo bar", "created": "2012-08-22T16:20:09.822"}' |
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(comment) | |
| print(serializer.data) | |
| # {'email': u'[email protected]', 'content': u'foo bar', 'created': datetime.datetime(2012, 8, 22, 16, 20, 9, 822774)} |
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 rest_framework import serializers | |
| class CommentSerializer(serializers.Serializer): | |
| email = serializers.EmailField() | |
| content = serializers.CharField(max_length=200) | |
| created = serializers.DateTimeField() | |
| def restore_object(self, attrs, instance=None): | |
| """ | |
| Учитывая словарь десериализованных значений поля, либо обновить существующий экземпляр модели или |
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
| class Comment(object): | |
| def __init__(self, email, content, created=None): | |
| self.email = email | |
| self.content = content | |
| self.created = created or datetime.datetime.now() | |
| comment = Comment(email='[email protected]', content='My content') |
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
| Авторизация\Регистрация | |
| https://github.com/jazzband/django-oauth-toolkit | |
| https://github.com/pennersr/django-allauth | |
| https://github.com/sunscrapers/djoser | |
| https://github.com/django-guardian/django-guardian | |
| https://github.com/flavors/django-graphql-jwt | |
| Защита входа | |
| https://github.com/jazzband/django-axes | |
| https://github.com/jazzband/django-defender |
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
| class User(UserBase): | |
| id: int | |
| is_active: bool | |
| class Config: | |
| orm_mode = True | |
| async def create_user(user: schemas.UserCreate): | |
| fake_hashed_password = user.password + "notreallyhashed" |
NewerOlder