近期在做网页时发现,用django渲染html时,老是报错:django报错:django.template.exceptions.TemplateDoesNotExist: file.html。网上搜了一大堆,大神们说需要修改setting.py中的EMPLATES 的 DIRS。仔细查看后,报错行代码为:
t=loader.get_template('src/right.html')
loader.get_template函数执行出错。后发现django版本问题。当时安装django方法为:
conda install django
这样默认安装的版本为django 1.11.3,替换为django 1.8:
conda install django==1.8
Collecting package metadata (current_repodata.json): done Solving environment: done ## Package Plan ## environment location: /home/heihei/software/anaconda2 added / updated specs: - django==1.8 The following packages will be downloaded: package | build ---------------------------|----------------- django-1.8 | py27_0 3.2 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free ------------------------------------------------------------ Total: 3.2 MB The following packages will be DOWNGRADED: django 1.11.3-py27_0 --> 1.8-py27_0 Proceed ([y]/n)? y Downloading and Extracting Packages django-1.8 | 3.2 MB | ############################################################################################################## | 100% Preparing transaction: done Verifying transaction: done Executing transaction: done
之后程序就可以完美运行了~
网友评论