diff --git a/.idea/.gitignore b/.idea/.gitignore
index 35410ca..1296681 100644
--- a/.idea/.gitignore
+++ b/.idea/.gitignore
@@ -1,8 +1,8 @@
-# 默认忽略的文件
+# Default ignored files
/shelf/
/workspace.xml
-# 基于编辑器的 HTTP 客户端请求
-/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
diff --git a/.idea/IT_Show.iml b/.idea/IT_Show.iml
new file mode 100644
index 0000000..0e6b474
--- /dev/null
+++ b/.idea/IT_Show.iml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index 5d2f836..ac7f1bf 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -1,15 +1,32 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -19,5 +36,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 6df2987..6649a8c 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,7 @@
-
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
index 5119d8d..7789f72 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -2,7 +2,7 @@
-
+
\ No newline at end of file
diff --git a/IT_Show/__init__.py b/IT_Show/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/IT_Show/asgi.py b/IT_Show/asgi.py
new file mode 100644
index 0000000..6872961
--- /dev/null
+++ b/IT_Show/asgi.py
@@ -0,0 +1,16 @@
+"""
+ASGI config for IT_Show project.
+
+It exposes the ASGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
+"""
+
+import os
+
+from django.core.asgi import get_asgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'IT_Show.settings')
+
+application = get_asgi_application()
diff --git a/IT_Show/settings.py b/IT_Show/settings.py
new file mode 100644
index 0000000..a63a0c2
--- /dev/null
+++ b/IT_Show/settings.py
@@ -0,0 +1,145 @@
+"""
+Django settings for IT_Show project.
+
+Generated by 'django-admin startproject' using Django 3.2.5.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.2/topics/settings/
+
+For the full list of settings and their values, see
+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
+
+
+# Quick-start development settings - unsuitable for production
+# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = 'django-insecure-f9_1pqmcnv!w0xp#vchj9e06_b-r!ahy@=w__j0^2#w2s)fa-o'
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+ALLOWED_HOSTS = []
+
+
+# Application definition
+
+INSTALLED_APPS = [
+ 'django.contrib.admin',
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.messages',
+ 'django.contrib.staticfiles',
+ 'rest_framework',
+ 'history',
+ 'comments',
+]
+
+MIDDLEWARE = [
+ 'django.middleware.security.SecurityMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.common.CommonMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+ 'django.middleware.clickjacking.XFrameOptionsMiddleware',
+]
+
+ROOT_URLCONF = 'IT_Show.urls'
+
+TEMPLATES = [
+ {
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'DIRS': [os.path.join(BASE_DIR, 'templates')]
+ ,
+ 'APP_DIRS': True,
+ 'OPTIONS': {
+ 'context_processors': [
+ 'django.template.context_processors.debug',
+ 'django.template.context_processors.request',
+ 'django.contrib.auth.context_processors.auth',
+ 'django.contrib.messages.context_processors.messages',
+ ],
+ },
+ },
+]
+
+WSGI_APPLICATION = 'IT_Show.wsgi.application'
+
+
+# Database
+# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.mysql',
+ 'NAME': "IT_Show",
+ 'PORT': '3306',
+ 'PASSWORD': 'Qq2442402635*',
+ 'USER': 'root',
+ 'HOST': '127.0.0.1'
+ }
+}
+
+
+# Password validation
+# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
+
+AUTH_PASSWORD_VALIDATORS = [
+ {
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
+ },
+]
+
+
+# Internationalization
+# https://docs.djangoproject.com/en/3.2/topics/i18n/
+
+LANGUAGE_CODE = 'zh-Hans'
+
+TIME_ZONE = 'Asia/Shanghai'
+
+USE_I18N = True
+
+USE_L10N = True
+
+USE_TZ = False
+
+
+# Static files (CSS, JavaScript, Images)
+# https://docs.djangoproject.com/en/3.2/howto/static-files/
+
+STATIC_URL = '/static/'
+STATIC_ROOT = os.path.join(BASE_DIR, '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'
+
+REST_FRAMEWORK = {
+ 'DEFAULT_RENDERER_CLASSES': ( # 默认响应渲染类
+ 'rest_framework.renderers.JSONRenderer', # json渲染器
+ 'rest_framework.renderers.BrowsableAPIRenderer', # 浏览API渲染器
+ )
+}
diff --git a/IT_Show/urls.py b/IT_Show/urls.py
new file mode 100644
index 0000000..e89d0fa
--- /dev/null
+++ b/IT_Show/urls.py
@@ -0,0 +1,28 @@
+"""IT_Show URL Configuration
+
+The `urlpatterns` list routes URLs to views. For more information please see:
+ https://docs.djangoproject.com/en/3.2/topics/http/urls/
+Examples:
+Function views
+ 1. Add an import: from my_app import views
+ 2. Add a URL to urlpatterns: path('', views.home, name='home')
+Class-based views
+ 1. Add an import: from other_app.views import Home
+ 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
+Including another URLconf
+ 1. Import the include() function: from django.urls import include, path
+ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
+"""
+from django.contrib import admin
+from django.urls import path, include, re_path
+from django.views.static import serve
+from IT_Show import settings
+
+
+urlpatterns = [
+ path('admin/', admin.site.urls),
+ path('api/', include('comments.urls')),
+ path('api/', include('history.urls')),
+ path(r'^api-auth/', include('rest_framework.urls')),
+ re_path(r'^media/(?P.*)', serve, {"document_root": settings.MEDIA_ROOT}),
+]
diff --git a/IT_Show/wsgi.py b/IT_Show/wsgi.py
new file mode 100644
index 0000000..160a818
--- /dev/null
+++ b/IT_Show/wsgi.py
@@ -0,0 +1,16 @@
+"""
+WSGI config for IT_Show project.
+
+It exposes the WSGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
+"""
+
+import os
+
+from django.core.wsgi import get_wsgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'IT_Show.settings')
+
+application = get_wsgi_application()
diff --git a/comments/__init__.py b/comments/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/comments/admin.py b/comments/admin.py
new file mode 100644
index 0000000..e71d85b
--- /dev/null
+++ b/comments/admin.py
@@ -0,0 +1,5 @@
+from django.contrib import admin
+from .models import Comments
+# Register your models here.
+
+admin.site.register(Comments)
diff --git a/comments/apps.py b/comments/apps.py
new file mode 100644
index 0000000..a90cc97
--- /dev/null
+++ b/comments/apps.py
@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+
+
+class CommentsConfig(AppConfig):
+ default_auto_field = 'django.db.models.BigAutoField'
+ name = 'comments'
diff --git a/comments/migrations/0001_initial.py b/comments/migrations/0001_initial.py
new file mode 100644
index 0000000..768a91f
--- /dev/null
+++ b/comments/migrations/0001_initial.py
@@ -0,0 +1,22 @@
+# Generated by Django 3.2.5 on 2022-04-15 14:15
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Comments',
+ fields=[
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('post_time', models.DateTimeField(verbose_name='发布时间')),
+ ('content', models.CharField(max_length=50, verbose_name='弹幕内容')),
+ ],
+ ),
+ ]
diff --git a/comments/migrations/__init__.py b/comments/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/comments/models.py b/comments/models.py
new file mode 100644
index 0000000..5bfc434
--- /dev/null
+++ b/comments/models.py
@@ -0,0 +1,11 @@
+from django.db import models
+
+# Create your models here.
+
+
+class Comments(models.Model):
+ post_time = models.DateTimeField(verbose_name="发布时间")
+ content = models.CharField(verbose_name="弹幕内容", max_length=50, blank=False)
+
+
+
diff --git a/comments/serializers.py b/comments/serializers.py
new file mode 100644
index 0000000..9d57096
--- /dev/null
+++ b/comments/serializers.py
@@ -0,0 +1,25 @@
+from rest_framework import serializers
+from .models import *
+
+
+class CommentsInfo(serializers.ModelSerializer):
+ class Meta:
+ model = Comments
+ fields = ['content', 'post_time']
+
+ post_time = serializers.DateTimeField(label="发布时间", required=False)
+ content = serializers.CharField(label="弹幕内容", max_length=50, required=True)
+
+ def validate_content(self, value):
+ ban = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', "_", "-"]
+ for i in ban:
+ if i in value:
+ raise serializers.ValidationError('非法字符')
+
+ if len(value) > 50:
+ raise serializers.ValidationError("弹幕过长")
+ elif len(value) == 0:
+ raise serializers.ValidationError("输入不能为空")
+
+
+ return value
diff --git a/comments/tests.py b/comments/tests.py
new file mode 100644
index 0000000..7ce503c
--- /dev/null
+++ b/comments/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/comments/urls.py b/comments/urls.py
new file mode 100644
index 0000000..f183407
--- /dev/null
+++ b/comments/urls.py
@@ -0,0 +1,9 @@
+from django.contrib import admin
+from django.urls import path
+from . import views
+
+urlpatterns = [
+ path('comment/', views.comments.as_view()),
+]
+
+
diff --git a/comments/views.py b/comments/views.py
new file mode 100644
index 0000000..3443607
--- /dev/null
+++ b/comments/views.py
@@ -0,0 +1,45 @@
+import time, datetime
+from django.conf import settings
+import re
+from django.shortcuts import render
+from rest_framework.views import APIView
+from rest_framework.response import Response
+from .models import *
+from .serializers import CommentsInfo
+from django.utils import timezone
+# Create your views here.
+
+
+class comments(APIView):
+
+ def get(self, request):
+ data = {}
+ queryset = Comments.objects.all()
+ serializer = CommentsInfo(queryset, many=True)
+ try:
+ data['data'] = serializer.data
+ except:
+ data['msg'] = serializer.error_messages
+ if len(data['data']) == 0:
+ data['msg'] = 'error'
+ data['code'] = "40000"
+ else:
+ data['msg'] = "success"
+ data['code'] = "20000"
+ return Response(data=data)
+
+
+ def post(self, request):
+ data = {}
+ serializer = CommentsInfo(data=request.data)
+ if not serializer.is_valid(raise_exception=True):
+ data['msg'] = serializer.error_messages
+ data['code'] = "40000"
+ return Response(data=data)
+ serializer.validated_data['post_time'] = timezone.now().replace(microsecond=0)
+ serializer.save()
+ data['data'] = serializer.validated_data
+ data['msg'] = "success"
+ data['code'] = "20000"
+ return Response(data=data)
+
diff --git a/history/__init__.py b/history/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/history/admin.py b/history/admin.py
new file mode 100644
index 0000000..b479430
--- /dev/null
+++ b/history/admin.py
@@ -0,0 +1,5 @@
+from django.contrib import admin
+from .models import History
+# Register your models here.
+
+admin.site.register(History)
diff --git a/history/apps.py b/history/apps.py
new file mode 100644
index 0000000..bff7de8
--- /dev/null
+++ b/history/apps.py
@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+
+
+class HistoryConfig(AppConfig):
+ default_auto_field = 'django.db.models.BigAutoField'
+ name = 'history'
diff --git a/history/migrations/0001_initial.py b/history/migrations/0001_initial.py
new file mode 100644
index 0000000..97c47b9
--- /dev/null
+++ b/history/migrations/0001_initial.py
@@ -0,0 +1,24 @@
+# Generated by Django 3.2.5 on 2022-04-15 14:20
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='History',
+ fields=[
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('grade', models.IntegerField(verbose_name='年份')),
+ ('name', models.CharField(max_length=30, verbose_name='事件名称')),
+ ('description', models.CharField(max_length=200, verbose_name='事件描述')),
+ ('img', models.ImageField(upload_to='', verbose_name='图片')),
+ ],
+ ),
+ ]
diff --git a/history/migrations/0002_alter_history_img.py b/history/migrations/0002_alter_history_img.py
new file mode 100644
index 0000000..dcda24d
--- /dev/null
+++ b/history/migrations/0002_alter_history_img.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.2.5 on 2022-04-15 14:32
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('history', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='history',
+ name='img',
+ field=models.ImageField(upload_to='image', verbose_name='图片'),
+ ),
+ ]
diff --git a/history/migrations/0003_alter_history_img.py b/history/migrations/0003_alter_history_img.py
new file mode 100644
index 0000000..3e20c30
--- /dev/null
+++ b/history/migrations/0003_alter_history_img.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.2.5 on 2022-04-15 23:05
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('history', '0002_alter_history_img'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='history',
+ name='img',
+ field=models.ImageField(upload_to='', verbose_name='图片'),
+ ),
+ ]
diff --git a/history/migrations/__init__.py b/history/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/history/models.py b/history/models.py
new file mode 100644
index 0000000..7780d83
--- /dev/null
+++ b/history/models.py
@@ -0,0 +1,11 @@
+from django.db import models
+
+# Create your models here.
+
+
+class History(models.Model):
+ grade = models.IntegerField(verbose_name="年份")
+ name = models.CharField(verbose_name="事件名称", max_length=30)
+ description = models.CharField(verbose_name="事件描述", max_length=200)
+ img = models.ImageField(verbose_name="图片", upload_to="image")
+
diff --git a/history/serializers.py b/history/serializers.py
new file mode 100644
index 0000000..11729e7
--- /dev/null
+++ b/history/serializers.py
@@ -0,0 +1,19 @@
+from rest_framework import serializers
+from .models import *
+
+
+class HistoryInfoSerializer(serializers.ModelSerializer):
+ class Meta:
+ model = History
+ fields = '__all__'
+ grade = serializers.CharField(label="年级", required=True)
+ name = serializers.CharField(label="事件名称", max_length=30, required=True)
+ description = serializers.CharField(label="事件描述", max_length=200, required=True)
+ img = serializers.ImageField(label="图片", required=False)
+
+ def validate_grade(self, value):
+ if not (2010 < value <= 2021):
+ raise serializers.ValidationError("不合法输入")
+ return value
+
+
diff --git a/history/tests.py b/history/tests.py
new file mode 100644
index 0000000..7ce503c
--- /dev/null
+++ b/history/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/history/urls.py b/history/urls.py
new file mode 100644
index 0000000..827f21f
--- /dev/null
+++ b/history/urls.py
@@ -0,0 +1,11 @@
+from django.contrib import admin
+from django.urls import path
+from . import views
+from django.conf.urls.static import static
+from IT_Show import settings
+
+urlpatterns = [
+ path('history/', views.history.as_view()),
+]
+
+urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
diff --git a/history/views.py b/history/views.py
new file mode 100644
index 0000000..581329f
--- /dev/null
+++ b/history/views.py
@@ -0,0 +1,37 @@
+import time
+from django.conf import settings
+import re
+from django.shortcuts import render
+from rest_framework.views import APIView
+from rest_framework.response import Response
+from .models import History
+from .serializers import HistoryInfoSerializer
+# Create your views here.
+
+
+class history(APIView):
+
+ def get(self, request):
+ key = []
+ data = {"data": key}
+ for i in range(2012, 2022):
+ temp = {}
+ try:
+ works_set = History.objects.filter(grade=i)
+ if works_set:
+ serializer = HistoryInfoSerializer(works_set, many=True)
+ temp['grade'] = i
+ temp['data'] = serializer.data
+ data['data'].append(temp)
+ except Exception:
+ pass
+ if len(data['data']) == 0:
+ data['code'] = 40000
+ data['msg'] = "error"
+ else:
+ data['code'] = 20000
+ data['msg'] = 'success'
+ return Response(data=data)
+
+
+
diff --git a/media/image/1.png b/media/image/1.png
new file mode 100644
index 0000000..28f55ae
Binary files /dev/null and b/media/image/1.png differ
diff --git a/media/image/180.bmp b/media/image/180.bmp
new file mode 100644
index 0000000..6644227
Binary files /dev/null and b/media/image/180.bmp differ
diff --git a/media/image/Exchange1.bmp b/media/image/Exchange1.bmp
new file mode 100644
index 0000000..99e7af9
Binary files /dev/null and b/media/image/Exchange1.bmp differ