Django模板6 [已关闭]

4sup72z8  于 2023-03-04  发布在  Go
关注(0)|答案(1)|浏览(114)

编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
7天前关闭。
Improve this question
模板不存在于/todo_list_templates/list.html请求方法:GET请求URL:http://127.0.0.1:8001/ Django版本:4.1.2异常类型:模板不存在异常值:
todo_列表_模板/列表. html异常位置:C:\用户\sachi\应用数据\本地\程序\Python\Python310\lib\站点包\django\模板\加载器. py,第19行,在get_template中在以下过程中引发:todo_list. views. index Python可执行文件:C:\用户\sachi\应用程序数据\本地\程序\Python\Python 310\Python. exe Python版本:3.10.5 Python路径:
["C:\用户\sachi\待堂应用程序"、"C:\用户\sachi\应用程序数据\本地\程序\Python\Python 310\Python 310.zip"、"C:\用户\sachi\应用程序数据\本地\程序\Python\Python 310\DLL"、"C:\用户\sachi\应用程序数据\本地\程序\Python\Python 310\lib"、"C:\用户\sachi\应用程序数据\本地\程序\Python\Python 310\lib"、"C:\用户\sachi\应用程序数据\本地\程序\Python\Python 310\站点包"]服务器时间:2023年2月24日,星期五07:00:37 +0000模板加载器事后Django尝试加载这些模板,按以下顺序:
使用引擎django:
django.template.loaders.filesystem.Loader:C:\用户\sachi\待办事项应用程序\模板\待办事项列表模板\列表. html(源文件不存在)www.example.com目录。加载程序:django.template.loaders.appC:\用户\sachi\应用程序数据\本地\程序\Python\Python 310\lib\站点包\django\贡献\身份验证\模板\待办事项列表模板\列表. html(源代码不存在) C:\Users\sachi\AppData\Local\Programs\Python\Python310\lib\site-packages\django\contrib\admin\templates\todo_list_templates\list.html (Source does not exist) django.template.loaders.app_directories.Loader: C:\Users\sachi\AppData\Local\Programs\Python\Python310\lib\site-packages\django\contrib\auth\templates\todo_list_templates\list.html (Source does not exist)
我什么都试过了,但都不能为我工作

ktecyv1j

ktecyv1j1#

我相信你正在试图检索一个数据库中不存在的记录。在这种情况下,如果你在异常中返回一些东西,消息将抛出,而不是上面的错误。

try:
    TemplateData= Template.objects.get(id=1 )
    return TemplateData
except Template.DoesNotExist:
    successMsg = {"success":"False","message":"Invalid Template"}
    return Response(status=status.HTTP_200_OK, data=successMsg)

希望这会有帮助。否则发布您的代码。

相关问题