账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    一个关于django的奇葩问题!TemplateDoesNotExist ,但显示的路径正确,文件存在
    35
    0

    问题描述

    TemplateDoesNotExist

    问题出现的环境背景及自己尝试过哪些方法

    查了不下50个网页,包括Google,stackoverflow等等

    相关代码

    // 请把代码文本粘贴到下方(请勿用图片代替代码)
    TemplateDoesNotExist at /single/433
    show_content/省略/433.html
    Request Method: GET
    Request URL: 省略
    Django Version: 2.1.1
    Exception Type: TemplateDoesNotExist
    Exception Value:
    show_content/省略/433.html
    Exception Location: /usr/local/lib/python3.6/dist-packages/django/template/loader.py in get_template, line 19
    Python Executable: /usr/local/bin/uwsgi
    Python Version: 3.6.3
    Python Path:
    ['.',
    '',
    '/usr/lib/python36.zip',
    '/usr/lib/python3.6',
    '/usr/lib/python3.6/lib-dynload',
    '/usr/local/lib/python3.6/dist-packages',
    '/usr/lib/python3/dist-packages']
    Server time: Sat, 20 Oct 2018 05:49:20 +0000
    Template-loader postmortem
    Django tried loading these templates, in this order:

    Using engine django:

    django.template.loaders.filesystem.Loader: /home/zhixing/templates/show_content/新浪/433.html (Source does not exist)
    django.template.loaders.app_directories.Loader: /usr/local/lib/python3.6/dist-packages/django/contrib/admin/templates/show_content/省略/433.html (Source does not exist)
    django.template.loaders.app_directories.Loader: /usr/local/lib/python3.6/dist-packages/django/contrib/auth/templates/show_content/省略/433.html (Source does not exist)

    奇葩之处在于,ubuntu 上权限没问题,错误页面显示的路径完全正确,我甚至能直接粘贴从xftp上打开这路径。
    项目发布到服务器前,是在win10上开发,一切正常,该修改的地方都修改了。包括继承模板的路径。
    项目用的是 Ubuntu14 + nginx + uwsgi + django

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 移动四级包 普通会员 1楼

      TemplateDoesNotExist 是 Django 中的一个异常,通常出现在尝试使用某个模板时,该模板并未找到。

      然而,这个异常并不总是意味着一个模板不存在。它可能是由于以下原因:

      1. 模板路径错误:在模板中指定的路径可能没有正确设置,或者路径的格式不正确。例如,如果你使用的是相对路径,但你的 settings.py 中的 TEMPLATES 配置没有正确地包含绝对路径,那么 TemplateDoesNotExist 就会出现。

      2. 模板文件不存在:即使你的模板文件存在,但是由于某些原因,例如文件路径错误或者权限问题,你可能无法访问它。

      3. 模板文件路径与应用程序目录冲突:如果你在 Django 应用程序的文件夹中创建了模板文件,但是该文件被另一个应用程序中的其他文件夹引用,那么也会导致 TemplateDoesNotExist

      解决这个问题的方法有很多。首先,你需要检查你的模板路径是否正确。确保你的 settings.py 中的 TEMPLATES 配置包含了正确的位置。然后,你也可以尝试在应用程序的文件夹中创建模板文件,或者在另一个应用程序的文件夹中引用模板文件。

      如果你仍然无法解决问题,那么可能是由于其他问题导致的,例如数据库连接问题或者模型错误等。在这种情况下,你可能需要查阅 Django 的文档,或者寻求其他开发者的帮助。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部