2025-04-14 12:11:23 +00:00
|
|
|
|
"""
|
|
|
|
|
|
URL configuration for maxkb project.
|
|
|
|
|
|
|
|
|
|
|
|
The `urlpatterns` list routes URLs to views. For more information please see:
|
|
|
|
|
|
https://docs.djangoproject.com/en/4.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'))
|
|
|
|
|
|
"""
|
2025-06-13 09:35:25 +00:00
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
from django.http import HttpResponse
|
2025-04-14 12:11:23 +00:00
|
|
|
|
from django.urls import path, re_path, include
|
|
|
|
|
|
from django.views import static
|
2025-04-17 06:27:58 +00:00
|
|
|
|
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView
|
2025-06-13 09:35:25 +00:00
|
|
|
|
from rest_framework import status
|
2025-04-14 12:11:23 +00:00
|
|
|
|
|
2025-06-13 09:35:25 +00:00
|
|
|
|
from common.result import Result
|
2025-04-14 12:11:23 +00:00
|
|
|
|
from maxkb import settings
|
2025-06-13 09:35:25 +00:00
|
|
|
|
from maxkb.conf import PROJECT_DIR
|
2025-04-14 12:11:23 +00:00
|
|
|
|
|
|
|
|
|
|
urlpatterns = [
|
|
|
|
|
|
path("api/", include("users.urls")),
|
2025-04-17 10:01:33 +00:00
|
|
|
|
path("api/", include("tools.urls")),
|
|
|
|
|
|
path("api/", include("models_provider.urls")),
|
2025-04-28 02:39:23 +00:00
|
|
|
|
path("api/", include("folders.urls")),
|
2025-04-25 09:06:40 +00:00
|
|
|
|
path("api/", include("knowledge.urls")),
|
2025-05-06 10:35:11 +00:00
|
|
|
|
path("api/", include("system_manage.urls")),
|
2025-05-30 12:02:39 +00:00
|
|
|
|
path("api/", include("application.urls")),
|
2025-06-13 09:35:25 +00:00
|
|
|
|
path("chat/api/", include("chat.urls")),
|
2025-06-06 03:42:31 +00:00
|
|
|
|
path('oss/', include('oss.urls')),
|
2025-04-14 12:11:23 +00:00
|
|
|
|
]
|
|
|
|
|
|
urlpatterns += [
|
|
|
|
|
|
path('schema/', SpectacularAPIView.as_view(), name='schema'), # schema的配置文件的路由,下面两个ui也是根据这个配置文件来生成的
|
|
|
|
|
|
path('doc/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'), # swagger-ui的路由
|
|
|
|
|
|
path('redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'), # redoc的路由
|
|
|
|
|
|
]
|
|
|
|
|
|
urlpatterns.append(
|
|
|
|
|
|
re_path(r'^static/(?P<path>.*)$', static.serve, {'document_root': settings.STATIC_ROOT}, name='static'),
|
|
|
|
|
|
)
|
2025-06-13 09:35:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pro():
|
|
|
|
|
|
# 暴露静态主要是swagger资源
|
|
|
|
|
|
urlpatterns.append(
|
|
|
|
|
|
re_path(r'^static/(?P<path>.*)$', static.serve, {'document_root': settings.STATIC_ROOT}, name='static'),
|
|
|
|
|
|
)
|
|
|
|
|
|
# 暴露ui静态资源
|
|
|
|
|
|
urlpatterns.append(
|
|
|
|
|
|
re_path(r'^ui/(?P<path>.*)$', static.serve, {'document_root': os.path.join(settings.STATIC_ROOT, "ui")},
|
|
|
|
|
|
name='ui'),
|
|
|
|
|
|
)
|
|
|
|
|
|
# 暴露ui静态资源
|
|
|
|
|
|
urlpatterns.append(
|
|
|
|
|
|
re_path(r'^chat/(?P<path>.*)$', static.serve, {'document_root': os.path.join(settings.STATIC_ROOT, "chat")},
|
|
|
|
|
|
name='chat'),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not settings.DEBUG:
|
|
|
|
|
|
pro()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_index_html(index_path):
|
|
|
|
|
|
file = open(index_path, "r", encoding='utf-8')
|
|
|
|
|
|
content = file.read()
|
|
|
|
|
|
file.close()
|
|
|
|
|
|
return content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def page_not_found(request, exception):
|
|
|
|
|
|
"""
|
|
|
|
|
|
页面不存在处理
|
|
|
|
|
|
"""
|
|
|
|
|
|
if request.path.startswith("/api/"):
|
|
|
|
|
|
return Result(response_status=status.HTTP_404_NOT_FOUND, code=404, message="HTTP_404_NOT_FOUND")
|
|
|
|
|
|
if request.path.startswith("/chat/api/"):
|
|
|
|
|
|
return Result(response_status=status.HTTP_404_NOT_FOUND, code=404, message="HTTP_404_NOT_FOUND")
|
|
|
|
|
|
if request.path.startswith('/chat'):
|
|
|
|
|
|
index_path = os.path.join(PROJECT_DIR, 'apps', "static", 'chat', 'index.html')
|
|
|
|
|
|
else:
|
|
|
|
|
|
index_path = os.path.join(PROJECT_DIR, 'apps', "static", 'ui', 'index.html')
|
|
|
|
|
|
if not os.path.exists(index_path):
|
|
|
|
|
|
return HttpResponse("页面不存在", status=404)
|
|
|
|
|
|
content = get_index_html(index_path)
|
|
|
|
|
|
return HttpResponse(content, status=200)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handler404 = page_not_found
|