Moved compatibility code into compat.py

This commit is contained in:
enrico 2022-08-20 09:39:49 +08:00
parent 7d2b73a024
commit 8fa1b7c2b7
2 changed files with 8 additions and 6 deletions

View File

@ -41,6 +41,13 @@ except ImportError:
uritemplate = None uritemplate = None
# async_to_sync is required for async View support
if django.VERSION >= (3, 1):
from asgiref.sync import async_to_sync
else:
async_to_sync = None
# coreschema is optional # coreschema is optional
try: try:
import coreschema import coreschema

View File

@ -3,7 +3,6 @@ Provides an APIView class that is the base of all views in REST framework.
""" """
import asyncio import asyncio
import django
from django.conf import settings from django.conf import settings
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.db import connections, models from django.db import connections, models
@ -15,17 +14,13 @@ from django.views.decorators.csrf import csrf_exempt
from django.views.generic import View from django.views.generic import View
from rest_framework import exceptions, status from rest_framework import exceptions, status
from rest_framework.compat import async_to_sync
from rest_framework.request import Request from rest_framework.request import Request
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.schemas import DefaultSchema from rest_framework.schemas import DefaultSchema
from rest_framework.settings import api_settings from rest_framework.settings import api_settings
from rest_framework.utils import formatting from rest_framework.utils import formatting
if django.VERSION >= (3, 1):
from asgiref.sync import async_to_sync
else:
async_to_sync = None
def get_view_name(view): def get_view_name(view):
""" """