https://cloud.tencent.com/developer/article/1005607
前端代码 build 后放入 Django 项目下
urls.py 添加两行
from django.views.generic import TemplateView
urlpatterns = [
path('dashboard/', TemplateView.as_view(template_name="index.html")),
]
TEMPLATES 添加 DIRS
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['dist'],
'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',
],
},
},
]
添加 STATICFILES_DIRS css/js 静态文件放进去
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "dist/static"),
]