首页 > 解决方案 > How does Django knows which template to render when?

问题描述

I am on 4th chapter the book Django 3 by example and I noticed one thing that we are only creating views from Django's authentication framework but we are not telling those views which template to render when. For example, how does my application would know that it needs to only render the logged_out.html template when we try to access the logout view? If I try to change the name of the file from logged_out.html to loggedout.html then it takes me to the Django's admin logout page.

Why?

标签: djangopython-3.xdjango-views

解决方案


在 django 视图中,对于我们在最后编写的每个视图

return render(request, 'your template location')

这就是 django 知道为哪个视图渲染哪个模板的方式。


推荐阅读