Skip to main content

django增强

Project description

TerminatorCore

Django的增强代码,不用手动添加路由,自带crud,代码生成器,简单的权限管理类,帮助缩减开发时间 仅限Django框架

1. 创建Django项目

2. pip install TerminatorCore

3. 配置

  • 在settings.py中引入TerminatorBaseCore

INSTALLED_APPS = [
    'TerminatorBaseCore',
]
  • 在urls.py中加入配置

load_custom_viewsets_from_directory方法directory参数为需要对外暴露的文件路径

'my_project/expose'意思为扫描该路径下的所有文件

from TerminatorBaseCore.route.load_custom_viewsets_from_directory import load_custom_viewsets_from_directory

urlpatterns = [
    *load_custom_viewsets_from_directory('my_project/expose'),
]
  • 使用基础代码生成器

from TerminatorBaseCore.utils.entity_export_util import generate_model_code

if __name__ == '__main__':
    generate_model_code('uploadfile_image', 'my_project', 'localhost', 'root', 'root', 'test_demo')

这里generate_model_code有以下参数
table_name 数据库表名
project_name 项目名称
host 数据库地址
user 数据库账号
password 数据库密码
database 数据库

生成器会在系统文档中生成model,expose,service文件,然后将文件复制到项目对应目录下即可

功能一

settings.py中加入,即可开启接口权限校验

PERMISSION_PATH = 'TerminatorBaseCore.service.authenticated_with_redis.AuthenticatedWithRedis'
from TerminatorBaseCore.utils.token_manger import TokenManager

# 通过TokenManager实现token的生成校验
# 用户登录成功后为其生成一个token
def user_login(request):
    user_id = 1
    email = "11"
    token = TokenManager().generate_token(user_id, email)
    
    # 为request赋予一个new_token属性,在返回结果后如果有这个属性会自动在响应头X-Token加入token,前端监听响应头中X-Token属性,有值则更新本地token
    request.new_token = token

    # token随请求头的Authorization传递

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

terminatorcore-0.1.9.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

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

TerminatorCore-0.1.9-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file terminatorcore-0.1.9.tar.gz.

File metadata

  • Download URL: terminatorcore-0.1.9.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for terminatorcore-0.1.9.tar.gz
Algorithm Hash digest
SHA256 f757b13377e9afb57a0a7ea8f027bb40d2d5d9ceeff9e7a523ddb0ec47d4cc74
MD5 0fd06261f3ccd197e3d9772705df9924
BLAKE2b-256 5ac1e28a72e8f245bfa5f31c250cf485a05c8210d555676351e11b471e5caf81

See more details on using hashes here.

File details

Details for the file TerminatorCore-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: TerminatorCore-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for TerminatorCore-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 6f0a708c9708c749bbb1a804fd6e5d43388b36fa5483a875e40394cd45dbeff9
MD5 58e7f073c030a603b7d324753f7b39ea
BLAKE2b-256 78a8f759e5e6c74cf48e321b016d861974410c60828a95a42ecd2fce123c4fd2

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