Django端
- setting.py
# 配置templates
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',
],
},
},
]
# static
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
- urls.py
from django.views.generic import TemplateView
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^$', TemplateView.as_view(template_name="index.html")),
]
vue-cli
- vue.config.js
module.exports = {
assetsDir: "static",
indexPath: "templates/index.html",
}
合并
将run build 生成的static 和 templates 文件夹拷贝到django项目
网站图标favicon.ico无法显示的解决:
- 将public中index.html中href="<%= BASE_URL %>favicon.ico"改为href=“static/favicon.ico”
- 重新run build
- 将favicon.ico文件放入static目录内