Python 后端文件夹中的URL.py文件-需要在前端文件夹中找到index.html
我需要从前端的公用文件夹传递index.html文件的路径 指向位于另一个后端文件夹中的后端中的URL.py文件 文件夹结构:Python 后端文件夹中的URL.py文件-需要在前端文件夹中找到index.html,python,python-3.x,django,vue.js,Python,Python 3.x,Django,Vue.js,我需要从前端的公用文件夹传递index.html文件的路径 指向位于另一个后端文件夹中的后端中的URL.py文件 文件夹结构: backend -> backend -> urls.py frontend -> public -> index.html 这里是我需要放置该路由的地方,以便python可以找到我的index.html文件 from django.contrib import admin from django
backend
-> backend
-> urls.py
frontend
-> public
-> index.html
这里是我需要放置该路由的地方,以便python可以找到我的index.html文件
from django.contrib import admin
from django.urls import include,path
from .routers import router
from django.views.generic import TemplateView
urlpatterns = [
path('', TemplateView.as_view(template_name = '../../public/index.html')),
]
我在前端使用VueJs,这就是为什么我希望有组织地工作,并在django中拥有专用的前端+后端库的原因。您可以在settings.py中配置templates文件夹,然后使用此文件夹中的路径。 像这样:
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['PATH_OF_YOU_TEMPLATES_FOLDER'], #Probably finished in ...public/
'APP_DIRS': True,
'OPTIONS': {
# ... some options here ...
},
},]
并输入url:
from django.contrib import admin
from django.urls import include,path
from .routers import router
from django.views.generic import TemplateView
urlpatterns = [
path('', TemplateView.as_view(template_name = 'index.html')),
]
您需要阅读django模板()的文档