在Django中找不到模板错误

2024-10-16 20:43:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经尝试了所有方法,并且在view.py中路径是正确的,但是在django中获取模板并没有发现错误 我的观点

def starting_page(request):
    return render(request,"tractor/index.html")

def posts(request):
    return render(request,"tractor/all-post.html")

我还添加了ss的错误和我的目录

enter image description hereenter image description here


Tags: django方法py路径view模板returnrequest
1条回答
网友
1楼 · 发布于 2024-10-16 20:43:23

我们可以尝试遵循docs中设置的结构,因此尝试将文件移动到应用程序中的以下位置(假设my_proj是django项目的名称tractor是应用程序的名称):

my_proj/tractor/templates/tractor/index.html
my_proj/tractor/templates/tractor/all-post.html

要确保找到这些html文件,请验证settings.py是否按照文档中的说明正确配置了该文件

First, make sure your template settings are checking inside app directories:

TEMPLATES = [
    {
        ...,
        'APP_DIRS': True,
        ...
    },
]

或者如果您的文件在项目中而不在应用程序中:

TEMPLATES = [
    {
        ...
        'DIRS': [BASE_DIR / 'templates'],
        ...
    },
]

相关问题 更多 >