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]$ 
  • 相关阅读:
    初探diskstats
    JVM参数简述
    304 Not Modified 简述
    vmstat命令
    iostat 工具分析I/O性能
    git添加公钥后报错sign_and_send_pubkey: signing failed: agent refused operation
    Mysql ibdata1简述
    Mysql 事务日志(Ib_logfile)
    django项目一:基于django2.2可重用登录与注册模块-前端页面配置
    django项目一:基于django2.2可重用登录与注册模块-url路由和视图
  • 原文地址:https://www.cnblogs.com/qinhan/p/8409737.html
Copyright © 2011-2022 走看看