24 Django模块的导入--常用总结

常用模块导入

1 forms

# forms组件的使用
from django import forms

2 ValidationError

# modelform报错时使用
from django.core.exceptions import ValidationError

3 mark_safe

# 标签的转义
from django.utils.safestring import mark_safe

4 HttpResponse, render, redirect

# Django常用操作
from django.shortcuts import HttpResponse, render, redirect

5 QueryDict

# Django的有序字典
from django.http import QueryDict

6 reverse

# Django反向生成url
from django.urls import reverse

7 transaction

# Django的事务锁
from django.db import transaction

8 settings

# Django的配置文件
from django.conf import settings

9 JsonResponse

# Django返回Json数据
from django.http import JsonResponse

10 transaction

# Django-事务模块
from django.db import transaction

11 Q & F

# Django-复杂搜索&条件模块
from django.db.models import Q
from django.db.models import F

12 messages

# Django-messages组件
from django.contrib import messages

13 get_redis_connection

# Django-redis模块
from django_redis import get_redis_connection

14 RegexValidator

# Django-forms&modelform正则验证模块
from django.core.validators import RegexValidator

常用报错导入

1 ValidationError

# Django-forms&modelform字段报错返回数据
from django.core.exceptions import ValidationError

rest_framework模块

1 APIView

# 视图继承的父类
from rest_framework.views import APIView

2 Response,Request

# 返回数据类
from rest_framework.response import Response
from rest_framework.request import Request

3 BaseAuthentication

# DRF认证类
from rest_framework.authentication import BaseAuthentication

4 BasePermission

# DRF权限类
from rest_framework.permissions import BasePermission

5 SimpleRateThrottle

# DRF限流类
from rest_framework.throttling import BaseThrottle, SimpleRateThrottle

6 serializers

# DRF序列化器
from rest_framework import serializers

1


1


1



rest_framework异常报错

1 AuthenticationFailed

# DRF认证类抛出异常
from rest_framework.exceptions import AuthenticationFailed
posted @ 2022-09-14 16:04  角角边  Views(199)  Comments(0Edit  收藏  举报