Skip to main content

接口授权模型

Project description

xy_django_app_api_auth

说明

接口授权模型.

源码仓库

安装

# bash
pip install xy_django_app_api_auth

使用

1. 直接引入
  • 1. 设置全局配置

在Django项目中的settings.py文件中加入如下配置 例如: settings.py

# settings.py

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "xy_django_app_api_auth",
    "Demo",
    "Resource",
    "Media",
]
  • 2. 运行项目
xy_web_server -w django makemigrations
xy_web_server -w django migrate
# 同步数据表
xy_web_server -w django start
# 启动工程后访问 http://127.0.0.1:8401/admin 验证接口授权管理系统
2. 自定义
  • 1. 创建ApiAuth模块

操作 样例工程

# bash
xy_web_server -w django startapp ApiAuth
# ApiAuth 模块创建在 source/Runner/Admin/ApiAuth 
  • 2. 设置全局配置

在Django项目中的settings.py文件中加入如下配置 例如: settings.py

# settings.py

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "Demo",
    "Resource",
    "Media",
    "ApiAuth",
]
# models.py
from django.db import models
from django.utils.translation import gettext_lazy as _
from xy_django_app_api_auth.abstracts import *


class MApiAuthCredential(MAApiAuthCredential):
    versions = models.ManyToManyField(
        "xy_django_app_information.MVersion",
        verbose_name=_("所属版本"),
        related_name="%(app_label)s_%(class)s_versions",
        blank=True,
    )

    class Meta:
        verbose_name = _("授权用户凭证")
        verbose_name_plural = _("授权用户凭证")
        app_label = "ApiAuth"


class MApiAuthCredentialCache(MAApiAuthCredentialCache):
    credential = models.ForeignKey(
        "ApiAuth.MApiAuthCredential",
        verbose_name=_("凭证"),
        related_name="%(app_label)s_%(class)s_credential",
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
    )

    class Meta:
        verbose_name = _("授权用户凭证缓存")
        verbose_name_plural = _("授权用户凭证缓存")
        app_label = "ApiAuth"
# admin.py
# -*- coding: UTF-8 -*-


from django.contrib import admin
from .models import *


# Register your models here.
@admin.register(MApiAuthCredential)
class AApiAuthCredential(admin.ModelAdmin):
    pass


@admin.register(MApiAuthCredentialCache)
class AApiAuthCredentialCache(admin.ModelAdmin):
    pass
  • 5. 运行项目
xy_web_server -w django makemigrations
xy_web_server -w django migrate
# 同步数据表
xy_web_server -w django start
# 启动工程后访问 http://127.0.0.1:8401/admin 验证接口授权管理系统

许可证

xy_django_app_api_auth 根据 <木兰宽松许可证, 第2版> 获得许可。有关详细信息,请参阅 LICENSE 文件。

捐赠

如果小伙伴们觉得这些工具还不错的话,能否请咱喝一杯咖啡呢?

Pay-Total

联系方式

微信: yuyangiit
邮箱: yuyangit.0515@qq.com

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

xy_django_app_api_auth-1.0.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

xy_django_app_api_auth-1.0.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file xy_django_app_api_auth-1.0.0.tar.gz.

File metadata

File hashes

Hashes for xy_django_app_api_auth-1.0.0.tar.gz
Algorithm Hash digest
SHA256 38418c10bbd9ec80b389d6c822a7cce332c15cf6ff9724cdffa1c14aff4b5fdf
MD5 bbccbf3da903cb509455e7e68cc62e7d
BLAKE2b-256 7bc65a67b7aee74e861758981a82962fd7f912a2bc31478ce4d330e9818a7965

See more details on using hashes here.

File details

Details for the file xy_django_app_api_auth-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for xy_django_app_api_auth-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff3c9d8049b21ae23714a12fb151e2f646d26154e6dc561c9ea0af70e4a1ae42
MD5 edd784333ebaaa1eed5fa6941046bce6
BLAKE2b-256 730d1ed4bec92c8c4ec1a17bef90650470b86ea63592234463010dc8be2a45f9

See more details on using hashes here.

Supported by

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