Files
chunyu_project/chunyu_project/urls.py
T

85 lines
3.3 KiB
Python

"""
URL configuration for chunyu_project project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/5.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.http import JsonResponse
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.views.generic import TemplateView
from django.views.i18n import set_language
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from utils.swagger_generator import GracefulOpenAPISchemaGenerator
from shorturl.views import ShortUrlRedirectView
def home_view(request):
return JsonResponse({
"service": "可乐平台 API",
"status": "running",
"version": "1.0.0",
"docs": "/swagger/",
"admin": "/admin/",
"endpoints": {
"articles": "/article/articles/",
"learn": "/learn/courses/",
"user": "/user/",
"api_directory": "/api/apidirectory/",
},
})
schema_view = get_schema_view(
openapi.Info(
title="ChunYu API",
default_version='v1',
description="ChunYu Project API Documentation",
),
public=True,
permission_classes=(permissions.AllowAny,),
generator_class=GracefulOpenAPISchemaGenerator,
)
urlpatterns = [
path('', home_view, name='home'),
path('i18n/setlang/', set_language, name='set_language'),
path('admin/', admin.site.urls),
path('swagger.json', schema_view.without_ui(cache_timeout=0), name='schema-json'),
path('swagger<format>/', schema_view.without_ui(cache_timeout=0), name='schema-json'),
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
path('test/slider-captcha/', TemplateView.as_view(template_name='test_slider_captcha.html'), name='test-slider-captcha'),
path('user/', include('user.urls')),
path('api/apidirectory/', include('apidirectory.urls')),
path('api/', include('api.urls')),
path('app/', include('app.urls')),
path('bug/', include('bug.urls')),
path('article/', include('article.urls')),
path('history/', include('history.urls')),
path('learn/', include('learn.urls')),
path('message/', include('message.urls')),
path('chat/', include('chat.urls')),
path('tool/', include('tool.urls')),
path('search/', include('search.urls')),
path('logs/', include('logs.urls')),
path('s/<str:code>/', ShortUrlRedirectView.as_view()),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += staticfiles_urlpatterns()