forked from kongfp/TP_Admin
31
0
Fork 1

支持本地media视频

pull/2/head
lishuang 2 years ago
parent a72191aa8a
commit 56b60a8bf1

@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.2/ref/settings/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
@ -39,12 +40,14 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'rest_framework',
'django_filters',
'corsheaders',
'app'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
@ -122,7 +125,27 @@ USE_TZ = False
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# 解决跨域
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_HEADERS = ["*"]
CORS_ORIGIN_WHITELIST = ()
# 对应的发送的请求的跨域
CORS_ALLOW_METHODS = (
'DELETE',
'GET',
'OPTIONS',
'PATCH',
'POST',
'PUT',
'VIEW',
)

@ -14,9 +14,19 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.urls import path, include, re_path
from django.views.static import serve
from django.conf.urls.static import static
from django.conf import settings
from .settings import MEDIA_ROOT
urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('app.urls'))
]
urlpatterns += [
re_path(r'^media/(?P<path>.*)$', serve, {'document_root': MEDIA_ROOT}),
]

@ -12,15 +12,15 @@ class TP(models.Model):
# 警号
police_id = models.CharField(max_length=50)
# 事件类型
event_type = models.IntegerField()
event_type = models.CharField(max_length=50)
# 是否违规
is_violation = models.BooleanField()
# 缩略图
small_image = models.CharField(max_length=50)
small_image = models.CharField(max_length=100)
# 相对时间
relative_time = models.FloatField()
# 视频路径
video_dir = models.CharField(max_length=50)
video_dir = models.CharField(max_length=100)
# 车牌号
car_number = models.CharField(max_length=50)
# 分析结果

@ -2,6 +2,7 @@ from django.shortcuts import render
# Create your views here.
from rest_framework import viewsets
from rest_framework.response import Response
from django_filters.rest_framework import DjangoFilterBackend
from app.models import TP
from app.serializers import SerialMyModel

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.
Loading…
Cancel
Save