Django:位于/的TemplateDoesNotExist

时间:2018-10-17 16:57:04

标签: python django

enter image description here

我正在尝试将Django项目从1.8升级到1.10。

我从

更改了视图功能
from django.shortcuts import render
from django.http import HttpResponse
from django.template import RequestContext, loader
from django.shortcuts import render
from django.core.mail import EmailMessage
from django.http import HttpResponseRedirect
from sellmyland.settings import DEFAULT_FROM_EMAIL
from ipware.ip import get_ip
import json
from myapp.forms import myform


def index(request):


    form = myform()

    # return render('longform.html', {"form": form}, context_instance=RequestContext(request))

return render(request, 'longform.html', {'form': form})

settings.py:

# TEMPLATE_DIRS = (
#     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
#     # Always use forward slashes, even on Windows.
#     # Don't forget to use absolute paths, not relative paths.
#     os.path.join(BASE_DIR, 'templates'),
# )

TEMPLATE_DIRS = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        # 'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'DIRS': os.path.join(os.path.dirname(BASE_DIR),'templates'),
        'APP_DIRS': True,
        'OPTIONS': {
            # some options
        },
    },
]

您可以在代码中看到注释掉的版本。我收到上面的错误。这是回溯:

Traceback:

File "E:...\lib\site-packages\django\core\handlers\exception.py" in inner
  42.             response = get_response(request)

File "E:...\lib\site-packages\django\core\handlers\base.py" in _legacy_get_response
  249.             response = self._get_response(request)

File "E:...\lib\site-packages\django\core\handlers\base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "E:...\lib\site-packages\django\core\handlers\base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "E:\ENVS\r3\sellmyland3\app1\views.py" in index
  30.     return render(request, 'longform.html', {'form': form})

File "E:...\lib\site-packages\django\shortcuts.py" in render
  30.     content = loader.render_to_string(template_name, context, request, using=using)

File "E:...\lib\site-packages\django\template\loader.py" in render_to_string
  67.         template = get_template(template_name, using=using)

File "E:...\lib\site-packages\django\template\loader.py" in get_template
  25.     raise TemplateDoesNotExist(template_name, chain=chain)

Exception Type: TemplateDoesNotExist at /
Exception Value: longform.html

我该如何工作?

1 个答案:

答案 0 :(得分:3)

新设置为TEMPLATES,而不是TEMPLATE_DIRS。