zoukankan      html  css  js  c++  java
  • django.template.exceptions.TemplateDoesNotExist: login.html 错误处理

    登陆Login界面时候报错

    Internal Server Error: /login/
    Traceback (most recent call last):
      File "/usr/local/python3/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
        response = get_response(request)
      File "/usr/local/python3/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
        response = self.process_exception_by_middleware(e, request)
      File "/usr/local/python3/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
        response = wrapped_callback(request, *callback_args, **callback_kwargs)
      File "/home/python/project/MyCrazyeyes/web/views.py", line 45, in login
        return render(request, 'login.html')
      File "/usr/local/python3/lib/python3.6/site-packages/django/shortcuts.py", line 36, in render
        content = loader.render_to_string(template_name, context, request, using=using)
      File "/usr/local/python3/lib/python3.6/site-packages/django/template/loader.py", line 61, in render_to_string
        template = get_template(template_name, using=using)
      File "/usr/local/python3/lib/python3.6/site-packages/django/template/loader.py", line 19, in get_template
        raise TemplateDoesNotExist(template_name, chain=chain)
    django.template.exceptions.TemplateDoesNotExist: login.html
    [03/Feb/2018 07:39:49] "GET /login/?next=/ HTTP/1.1" 500 76432

    在setting.py下DIRS如下所示

    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',
                ],
            },
        },
    ]

    在setting.py重新设置下DIRS如下所示,则问题解决

    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
    #        'DIRS': [],
            'DIRS': ["%s/%s" %(BASE_DIR,'templates'),],
            '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',
                ],
            },
        },
    ]

    另外需要确保templates目录下确实是有login.html文件

    [python@qinhan templates]$ pwd
    /home/python/project/MyCrazyeyes/templates
    [python@qinhan templates]$ ls
    login.html
    [python@qinhan templates]$ 
  • 相关阅读:
    LeetCode(35):Palindrome Number 分类: leetCode 2015-07-10 09:26 161人阅读 评论(0) 收藏
    在pycharm进行单元测试(unittest python)
    Django 基本操作
    Django中数据库操作相关的错误
    Question&&Answer
    ubuntu下 SVN 服务器搭建及使用
    python 在不同层级目录import 模块的方法
    Ubuntu 16.04安装PyCharm
    修改mysql中数据库存储主路径
    查看mysql的数据库物理存放位置
  • 原文地址:https://www.cnblogs.com/qinhan/p/8409737.html
Copyright © 2011-2022 走看看