feat: update medical training case and auth modules
This commit is contained in:
+16
-16
@@ -1,16 +1,16 @@
|
||||
"""
|
||||
ASGI config for config 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/6.0/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
"""
|
||||
ASGI config for config 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/6.0/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||
|
||||
application = get_asgi_application()
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
"""健康检查:服务存活与数据库连通性。"""
|
||||
|
||||
from django.db import connection
|
||||
from django.db.utils import OperationalError
|
||||
from rest_framework.decorators import api_view, permission_classes
|
||||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework.response import Response
|
||||
|
||||
|
||||
@api_view(['GET', 'HEAD'])
|
||||
@permission_classes([AllowAny])
|
||||
def ping(request):
|
||||
"""服务存活探测,通则返回 ok。"""
|
||||
return Response('ok')
|
||||
|
||||
|
||||
@api_view(['GET', 'HEAD'])
|
||||
@permission_classes([AllowAny])
|
||||
def test_mysql(request):
|
||||
"""MySQL 连通探测:使用 Django 连接池建立连接,通则 ok,否则返回没连通。"""
|
||||
try:
|
||||
connection.ensure_connection()
|
||||
except OperationalError:
|
||||
return Response('没连通', status=503)
|
||||
except Exception:
|
||||
return Response('没连通', status=503)
|
||||
return Response('ok')
|
||||
@@ -12,7 +12,10 @@ import time
|
||||
api_logger = logging.getLogger('api_access')
|
||||
|
||||
# 跳过日志的路径前缀(静态文件、admin 等)
|
||||
_SKIP_PREFIXES = ('/static/', '/admin/', '/api/schema/', '/api/docs/')
|
||||
_SKIP_PREFIXES = (
|
||||
'/static/', '/admin/', '/api/schema/', '/api/docs/',
|
||||
'/api/ping/', '/api/testmysql/',
|
||||
)
|
||||
|
||||
# 请求体/响应体最大记录长度(字符)
|
||||
_MAX_BODY_LEN = 2000
|
||||
|
||||
+7
-1
@@ -10,7 +10,12 @@ SECRET_KEY = 'django-insecure-!-mtect5n-yyxkp2m=j(8dz_yi$b3w3ddo&w#i(@4kv-spdthy
|
||||
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
ALLOWED_HOSTS = [
|
||||
"127.0.0.1",
|
||||
"localhost",
|
||||
"192.168.2.76",
|
||||
"8.160.178.88"
|
||||
]
|
||||
|
||||
|
||||
INSTALLED_APPS = [
|
||||
@@ -160,6 +165,7 @@ CACHES = {
|
||||
SMS_CODE_EXPIRE = 300 # 验证码有效期(秒)
|
||||
SMS_CODE_INTERVAL = 60 # 发送间隔(秒)
|
||||
SMS_PROVIDER = os.getenv('SMS_PROVIDER', 'mock')
|
||||
SMS_MOCK_CODE = os.getenv('SMS_MOCK_CODE', '123456') # mock 模式下固定验证码
|
||||
|
||||
ALIYUN_SMS_ACCESS_KEY_ID = os.getenv('ALIYUN_SMS_ACCESS_KEY_ID', '')
|
||||
ALIYUN_SMS_ACCESS_KEY_SECRET = os.getenv('ALIYUN_SMS_ACCESS_KEY_SECRET', '')
|
||||
|
||||
+44
-38
@@ -1,38 +1,44 @@
|
||||
"""
|
||||
URL configuration for config project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/6.0/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
|
||||
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView
|
||||
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView, SpectacularRedocView
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
|
||||
# API Routes
|
||||
path('api/user/', include('apps.user.urls')),
|
||||
path('api/case/', include('apps.case.urls')),
|
||||
path('api/training/', include('apps.training.urls')),
|
||||
|
||||
# JWT Token
|
||||
path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
|
||||
path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
|
||||
|
||||
# API Documentation
|
||||
path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
|
||||
path('api/docs/swagger/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
|
||||
path('api/docs/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
|
||||
]
|
||||
"""
|
||||
URL configuration for config project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/6.0/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
|
||||
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView
|
||||
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView, SpectacularRedocView
|
||||
|
||||
from config.health import ping, test_mysql
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
|
||||
# 健康检查(无需登录)
|
||||
path('api/ping/', ping),
|
||||
path('api/testmysql/', test_mysql),
|
||||
|
||||
# API Routes
|
||||
path('api/user/', include('apps.user.urls')),
|
||||
path('api/case/', include('apps.case.urls')),
|
||||
path('api/training/', include('apps.training.urls')),
|
||||
|
||||
# JWT Token
|
||||
path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
|
||||
path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
|
||||
|
||||
# API Documentation
|
||||
path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
|
||||
path('api/docs/swagger/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
|
||||
path('api/docs/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
|
||||
]
|
||||
|
||||
+16
-16
@@ -1,16 +1,16 @@
|
||||
"""
|
||||
WSGI config for config 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/6.0/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
"""
|
||||
WSGI config for config 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/6.0/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||
|
||||
application = get_wsgi_application()
|
||||
|
||||
Reference in New Issue
Block a user