Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 后端文件夹中的URL.py文件-需要在前端文件夹中找到index.html_Python_Python 3.x_Django_Vue.js - Fatal编程技术网

Python 后端文件夹中的URL.py文件-需要在前端文件夹中找到index.html

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

我需要从前端的公用文件夹传递index.html文件的路径 指向位于另一个后端文件夹中的后端中的URL.py文件

文件夹结构:

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模板()的文档