Skip to main content

Django-API-Utils是基于Django编写后端API的一些组件和工具,致力于努力探究 Django 最佳实践。

Project description

项目说明

Django-API-Utils是基于Django编写后端API的一些组件和工具,致力于努力探究 Django 最佳实践。

目前基于 ITM-0011 中的规范编写,仍待完善和在实践中优化。

环境依赖

目前已在 Django 3 下测试可以成功运行。

环境要求:

Django >= 3.2, djangorestframework >= 3.12 , djangorestframework-simplejwt >= 5.0.0 (如果不使用认证组件,将auth.py删除即可,不必安装此模块)

初始化项目

  1. 下载本项目源码,将utils文件夹拖到项目根目录下

    下载本项目源码可以使用git工具、直接在Github上Download ZIP、或者下载发布的release包。

  2. 新建apps目录,将项目内的app放入apps文件夹内。

  3. settings.py文件内,新增apps目录到BASE_DIR

    ...
    BASE_DIR = Path(__file__).resolve().parent.parent
    # 新增下面这一行
    sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))
    ...
    
  4. 在根路由文件urls.py下初始化Router Build

    from utils.router_builder import RouterBuilder
    router = RouterBuilder()
    urlpatterns = [
        path("api/", include(router.urls)),
        path("api/", include(router.url_patterns)),
    ]
    
  5. (非必需)在项目根目录下新建config.json文件,将项目的一些配置信息和敏感信息写到json文件中,并在settings.py中读取

    import json
    
    # Configuration File
    with open('./conf.json', 'r') as f:
        config = json.load(f)
    
    SECRET_KEY = config.get('SECRET_KEY','')
    
    MYSQL_DB_NAME = config.get('MYSQL_DB_NAME','')
    MYSQL_DB_USER = config.get('MYSQL_DB_USER','')
    MYSQL_DB_PASSWORD = config.get('MYSQL_DB_PASSWORD','')
    

    这样的好处在于,避免将敏感信息暴露到Git服务器上。

初始化完后,项目的目录树大概是这样的:

.
├── apps
│   ├── __init__.py
│   └── <app_name>
│       ├── __init__.py
│       ├── admin.py
│       ├── apps.py
│       ├── migrations
│       │   └── __init__.py
│       ├── models.py
│       ├── serializers.py
│       ├── tests.py
│       └── views.py
├── <project_name>
│   ├── __init__.py
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── .gitignore
├── manage.py
└── config.json[可选]

使用教程

更多详细信息请参考在线文档

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

it-drf-utils-0.2.2.tar.gz (11.6 kB view details)

Uploaded Source

Built Distributions

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

it_drf_utils-0.2.3-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

it_drf_utils-0.2.2-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file it-drf-utils-0.2.2.tar.gz.

File metadata

  • Download URL: it-drf-utils-0.2.2.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for it-drf-utils-0.2.2.tar.gz
Algorithm Hash digest
SHA256 26c0a0d14514fd62639163cc1e0f9e55990055c8977f0526b3ac6bd0d94d490c
MD5 496a19079cfacb9b654a33bdacd5cdc0
BLAKE2b-256 042f4e18ffded54ea6bc6ae345acedf56f4537dfe1b0d377e804831d7cf3ff37

See more details on using hashes here.

File details

Details for the file it_drf_utils-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: it_drf_utils-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for it_drf_utils-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9cdb383bee8abd8e65eeaf2430873855cb7677b3f3886425cd3dc67ebd7a0743
MD5 558e45f8e771595d09569950b2696b00
BLAKE2b-256 a4302c33f2b9a1d6876c6d87536cb417ea2d24b37240b65cdc25586227025b96

See more details on using hashes here.

File details

Details for the file it_drf_utils-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: it_drf_utils-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for it_drf_utils-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2152b70325f1708f8f39c4ee1f67a6b22dca461d0688bd44c7c0394e9e9d5db4
MD5 4848ffc91d807f5727d07829dfec2607
BLAKE2b-256 760d325936bd88b0d95100a179185bd91827fcdf8665a489f82e3719bbd10399

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