Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.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/0/jpa/2.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 如何将index.html连接到我的views.py?_Python_Django - Fatal编程技术网

Python 如何将index.html连接到我的views.py?

Python 如何将index.html连接到我的views.py?,python,django,Python,Django,我试着这样做: 但我的网页上说TemplateDoesNotExist 我该怎么办?在templates目录下创建一个文件夹“justcolor”,并在其中保存index.html。将路径更改为“justcolor/index.html”。返回render(请求'justcolor/index.html')确保正确配置了url.py和views.py 这里已经回答了这个问题:在justColor文件夹中创建一个templates\justColor子目录模板,然后将index.html移动到

我试着这样做:

但我的网页上说TemplateDoesNotExist


我该怎么办?

在templates目录下创建一个文件夹“justcolor”,并在其中保存index.html。将路径更改为“justcolor/index.html”。返回render(请求'justcolor/index.html')

确保正确配置了url.py和views.py


这里已经回答了这个问题:

justColor
文件夹中创建一个
templates\justColor
子目录模板,然后将
index.html
移动到那里。然后,正如@Neeraj所说,您可以将render调用更改为
render(请求'justColor/index.html')


(尽管你应该阅读django教程的这一部分,它比任何尝试和错误都更能帮助你:)

这是否回答了你的问题<代码>模板最好是应用程序的子目录,而不是项目的子目录。我认为模板路径也是区分大小写的,所以它是
justColor/index.html
我没有这个项目的应用程序。这只是我的项目的子目录,我得到了答案。谢谢我能够独自解决自己的问题。事实上,我在这里发布了这个问题的正确答案。不过还是谢谢你,我知道答案了。谢谢我能够独自解决自己的问题。事实上,我在这里发布了这个问题的正确答案。不过还是谢谢你,我知道答案了。谢谢我能够独自解决自己的问题。事实上,我在这里发布了这个问题的正确答案。不过还是谢谢你。@ZeddrixFabian你可能已经更改了
settings.py
上的
DIRS
变量来添加模板目录,对吗?当你在设置文件上启用应用程序时,我的答案是次要选项。
from django.http import HttpResponse
from django.shortcuts import render

def home(request):
    return render(request, 'templates/index.html')