Skip to main content

快速构建 RESTful API

Project description

Dseagull

快速构建 RESTful API


INSTALLED_APPS

添加 dseagull 到 INSTALLED_APPS 中, 注意必须要放在 rest_framework 前面

INSTALLED_APPS = [
    ...
    'dseagull',
    'rest_framework',
]

MIDDLEWARE

添加 dseagull.logger.LoggerMiddleware 到 MIDDLEWARE 中, 用于收集日志的字段

MIDDLEWARE = [
    'dseagull.logger.LoggerMiddleware',
    ...
]

REST_FRAMEWORK

不需要配置 REST_FRAMEWORK, 默认配置如下:

REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS': 'dseagull.pagination.PageNumberPagination',
    'PAGE_SIZE': 10,
    'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',
    'DEFAULT_FILTER_BACKENDS': [
        'django_filters.rest_framework.DjangoFilterBackend',
        'rest_framework.filters.SearchFilter',
        'rest_framework.filters.OrderingFilter',
    ],
    
}

serializers.Field

支持 required=True 时提示带上字段的 help_text 信息

from rest_framework.serializers import Serializer
class ExampleSerializer(Serializer):
    name = field(help_text='姓名')
ExampleSerializer(data={}).is_valid()

原本提示:这个字段是必填项。

现提示:姓名:这个字段是必填项。


支持 required=True, null=False 时提示带上字段的 help_text 信息

from rest_framework.serializers import Serializer
class ExampleSerializer(Serializer):
    name = field(help_text='姓名')
ExampleSerializer(data={'name': None}).is_valid()

原本提示:This field may not be null. 现提示:姓名:不能为空。


支持 required=True, null=False 时提示带上字段的 help_text 信息

from rest_framework.serializers import Serializer
class ExampleSerializer(Serializer):
    name = field(help_text='姓名')
ExampleSerializer(data={'name': ''}).is_valid()

原本提示:This field may not be blank. 现提示:姓名:不能为空白。


JWT

简化对称加密型的 JWT 编码和解码的过程, 需要配置 JWT_KEY 和 JWT_EXP,

from dseagull.djwt import JWTHS256
token = JWTHS256().encode({'username': 'admin'})
payload = JWTHS256().decode(token)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dseagull-0.0.12.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dseagull-0.0.12-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file dseagull-0.0.12.tar.gz.

File metadata

  • Download URL: dseagull-0.0.12.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for dseagull-0.0.12.tar.gz
Algorithm Hash digest
SHA256 2a78077bacfdca3309c8bc782a49865a917ddbb57f99221c97e6f6f074106232
MD5 ff52a87a1a247dc742347533eda0650f
BLAKE2b-256 674faf595c6823ddfc7c40497bde00ea9d9ad766d80108b138dcd1b39e3eedbd

See more details on using hashes here.

File details

Details for the file dseagull-0.0.12-py3-none-any.whl.

File metadata

  • Download URL: dseagull-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for dseagull-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 7604cc0c81fdfa7980faaa575ab71387752b7dea6fed55147afc0d434e82137a
MD5 fdf1e72548cb1b302fa0da5c97f9e772
BLAKE2b-256 68541c72348ce423c5300ce645430957491336a33a9544ca1b42031b338e15c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page