【问题标题】:TemplateDoesNotExist : Template Not being detected on DjangoTemplateDoesNotExist :在 Django 上未检测到模板
【发布时间】:2023-03-04 07:03:03
【问题描述】:

感谢登陆我的关心。 如果您能帮助我,我将不胜感激。

早些时候我正在执行相同的程序来获取模板,那时工作正常。但最近我尝试制作另一个项目,这次,出现“TemplateDoesNotExist”错误。

technicalcourses/Courses.html
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 3.0.4
Exception Type: TemplateDoesNotExist
Exception Value:    
technicalcourses/Courses.html
Exception Location: C:\Program Files\Python37\lib\site-packages\django\template\loader.py in get_template, line 19
Python Executable:  C:\Program Files\Python37\python.exe
Python Version: 3.7.4
Python Path:    
['C:\\Users\\ravik\\Desktop\\Django_New_Project\\edureka',
 'C:\\Program Files\\Python37\\python37.zip',
 'C:\\Program Files\\Python37\\DLLs',
 'C:\\Program Files\\Python37\\lib',
 'C:\\Program Files\\Python37',
 'C:\\Program Files\\Python37\\lib\\site-packages',
 'C:\\Program Files\\Python37\\lib\\site-packages\\win32',
 'C:\\Program Files\\Python37\\lib\\site-packages\\win32\\lib',
 'C:\\Program Files\\Python37\\lib\\site-packages\\Pythonwin']
Server time:    Sun, 31 May 2020 19:54:29 +0000

模板加载器事后分析 Django 尝试按以下顺序加载这些模板:

使用引擎 django:

django.template.loaders.filesystem.Loader: C:\Users\ravik\Desktop\Django_New_Project\edureka\template\technicalcourses\Courses.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Program Files\Python37\lib\site-packages\django\contrib\admin\templates\technicalcourses\Courses.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Program Files\Python37\lib\site-packages\django\contrib\auth\templates\technicalcourses\Courses.html (Source does not exist)

****下面我已经完成了-请附上图片****

【问题讨论】:

  • 请将您的代码添加为文本。
  • 这是模板目录而不是模板。也许正因为如此,您会遇到错误。并将您的 app_name 添加到 settings.py 中的 INSTALLED_APP

标签: django python-3.x templates django-views django-templates


【解决方案1】:

在你的 settings.py 文件中,你应该知道你的模板路径:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        ...
    },
]

https://docs.djangoproject.com/en/3.0/topics/templates/

【讨论】:

    猜你喜欢
    • 2019-08-08
    • 2015-06-13
    • 2016-01-22
    • 2012-10-25
    • 2012-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-21
    相关资源
    最近更新 更多