模板Django(在/不存在) [英] Templates Django (Does not exist at/)

查看:66
本文介绍了模板Django(在/不存在)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Django模板,但我什至无法显示简单的html行,我不明白为什么...我进行了搜索以解决此问题,但经过多次测试,问题仍然存在.

I'm trying to use the Django templates but i cant even display a simple html line i don't understand why... I searched to resolve it but after many test, the problem remains.

这是我的结构:

我的urls.py(我在views.py中尝试了另一种功能进行了尝试):

from django.conf.urls import patterns,include, url
from django.contrib import admin

urlpatterns = patterns('polls.views',

         url(r'^$', 'home', name = 'home'),
         url(r'^admin/', include(admin.site.urls)),
)

我的views.py:

from django.shortcuts import render
from django.template import Template , Context

# Create your views here.
# -*- coding: utf-8 -*-

def home(request):
    return render(request, 'mysite/bap2pmonitoring.html')

我的设置文件setting.py:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(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',
            ],
        },
    },
]

我的简单html文档:

<h1> BAP2P Monitoring </h1>

最后输出是我的主要问题:

这是回溯:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 1.8.1
Python Version: 2.7.3
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')

Template Loader Error:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/mysite/bap2pmonitoring.html (File does not exist)
/usr/local/lib/python2.7/dist-packages/django/contrib/auth/templates/mysite/bap2pmonitoring.html (File does not exist)



Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/florian/Documents/mysite/polls/views.py" in home
  8.    return render(request, 'mysite/bap2pmonitoring.html')
File "/usr/local/lib/python2.7/dist-packages/django/shortcuts.py" in render
  67.             template_name, context, request=request, using=using)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py" in render_to_string
  98.             template = get_template(template_name, using=using)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py" in get_template
  46.     raise TemplateDoesNotExist(template_name)

Exception Type: TemplateDoesNotExist at /
Exception Value: mysite/bap2pmonitoring.html

出于主意,请问您.谢谢您的时间

Out of ideas, i need your opinion please. Thanks for your time

推荐答案

P.S:请编辑您的问题,而不要在问题中添加答案:P

P.S: Please edit your question instead of adding an answer to your question with a question :P

出现错误

在目录结构中,您有两个模板目录,一个位于主项目中,另一个位于 mysite/polls/mysite/的民意调查应用程序中.Django正在项目模板中寻找模板,即

From your directory structure, you have two template directories, one in the main project and other in the polls app at mysite/polls/mysite/. Django is looking for templates in the project templates i.e.,

/home/florian/Documents/mysite/templates/mysite/bap2pmonitoring.html

/home/florian/Documents/mysite/templates/mysite/bap2pmonitoring.html

但是您的模板位于

/home/florian/Documents/mysite/polls/templates/mysite/bap2pmonitoring.html

/home/florian/Documents/mysite/polls/templates/mysite/bap2pmonitoring.html

将模板放在主项目模板目录中,它应该可以工作.

Put your templates in the main project template directory and it should work.

这篇关于模板Django(在/不存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆