我有一个名为“homepage.html”的html模板,我的项目设置如下:
但是,在运行时,我会遇到以下错误:
django.template.loaders.filesystem.Loader: D:\lirdi\python\django_blog_project\djangonautic\home\homepage.html (Source does not exist)
django.template.loaders.app_directories.Loader: D:\lirdi\python\django_blog_project\interpreter\lib\site-packages\django\contrib\admin\templates\home\homepage.html (Source does not exist)
django.template.loaders.app_directories.Loader: D:\lirdi\python\django_blog_project\interpreter\lib\site-packages\django\contrib\auth\templates\home\homepage.html (Source does not exist)
以下是我的模板代码:
<html>
<head>
<title>Homepage</title>
</head>
<body>
<h1>This is the homepage</h1>
<p>Welcome to Djangonautic</p>
</body>
</html>
在我看来:
def homepage(reqeust):
return render(reqeust,'home/homepage.html')
在我的设置文件中:
'DIRS': ['templates'],
模板
home/homepage.html
在您指定的位置不存在(我看不到名为“home
”的文件夹)。理想情况下,templates文件夹应该位于更高级别的目录中,直接位于第一个djangonautic
文件夹下尝试将templates文件夹移动到
django_blog_project/djangonautic/templates
,只需使用:确保在
settings.py
文件中正确指定了主模板目录,例如:相关问题 更多 >
编程相关推荐