Django模板报TemplateDoesNotExist异常(亲测可行)
作者:愤怒的软绵绵 时间:2023-11-02 18:53:49
环境
Django 2.0 + Win 10 + Pycharm + 360浏览器
报错
项目结构(报异常)
解决方法
看了好多大佬的解决方法,基本上都是配置settings.py文件,配来配去搞了好几个小时,依然没有解决问题。
后来发现,提示说的是templates路径下找不到文件,那么我们就在项目里面自己建个文件夹,命名为templates。
运行发现,还是有问题,还是找不到html,修改路由啥的搞了一通,还是没用。
经过多次实验,发现了正解:在templates下新建个文件夹,与应用名称相同(我的是indexpage),再把html放到路径下,终于可以访问了!
项目结构(已解决)
代码(已解决)
indexpage/views.py
... ...
def get_login_page(request):
return render(request, "indexpage/login.html")
... ...
indexpage/urls.py
from django.urls import path, include
import indexpage.views
urlpatterns = [
path('hello',indexpage.views.helloworld),
path('login', indexpage.views.get_login_page),
]
settings.py(保持默认)
... ...
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# print(BASE_DIR)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
... ...
来源:https://blog.csdn.net/qq_25742923/article/details/104568889
标签:Django,TemplateDoesNotExist,异常
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Vue CLI3.0中使用jQuery和Bootstrap的方法
2023-07-02 17:08:15
![](https://img.aspxhome.com/file/2023/5/139945_0s.jpg)
在MySQL数据库中如何来复位根用户的密码
2008-12-03 16:57:00
从零开始学YII2框架(五)快速生成代码工具 Gii 的使用
2024-05-11 09:54:56
![](https://img.aspxhome.com/file/2023/9/125819_0s.png)
Python多进程库multiprocessing中进程池Pool类的使用详解
2022-11-22 03:21:11
![](https://img.aspxhome.com/file/2023/6/105456_0s.png)
百分百弹窗
2013-08-07 07:41:06
Python中encode()方法的使用简介
2023-09-22 15:26:38
python生成n个元素的全组合方法
2023-11-10 20:35:08
MyEclipse连接MySQL数据库报错解决办法
2024-01-18 03:31:37
![](https://img.aspxhome.com/file/2023/6/77206_0s.jpg)
网页设计趋势之:”勾引”用户的按钮
2009-02-17 12:09:00
![](https://img.aspxhome.com/file/UploadPic/20092/17/but-500x47-23s.gif)
使用python实现学生信息管理系统
2022-11-24 21:28:35
利用Python+PyQt5实现简易浏览器的实战记录
2022-10-30 23:16:26
![](https://img.aspxhome.com/file/2023/3/77853_0s.png)
Mysql| 使用通配符进行模糊查询详解(like,%,_)
2024-01-15 08:17:40
如何正确合理的建立MYSQL数据库索引
2010-10-25 20:08:00
跟老齐学Python之有点简约的元组
2022-04-11 10:21:43
MySQL 启动成功但未监听端口的解决方法
2024-01-29 00:01:55
![](https://img.aspxhome.com/file/2023/2/112632_0s.png)
关于django 数据库迁移(migrate)应该知道的一些事
2024-01-24 08:42:50
Python类的用法实例浅析
2023-07-31 11:17:18
驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接,错误:“The server selected protocol version TLS10 is not accepted by client
2024-01-14 21:42:28
![](https://img.aspxhome.com/file/2023/2/110942_0s.png)
python可以用哪些数据库
2024-01-19 11:43:51
Python使用lambda表达式对字典排序操作示例
2022-12-26 06:27:46