如何让django知道模板目录?

时间:2014-08-20 21:22:40

标签: python django python-2.7 django-templates

我正在尝试使用Django书来探索探戈并构建Rango应用程序,但现在我不知道如何让django知道我的模板'目录:

Views.py:

from django.http import HttpResponse
from django.template import RequestContext
from django.shortcuts import render_to_response 

def index(request):
    context = RequestContext(request)
    context_dict = {'boldmessage': "I am bold"} 
    return render_to_response('/rango/index.html', context_dict, context)
def about(request):
    return HttpResponse("Hello Amir")

Settings.py:

import os

SETTINGS_DIR = os.path.dirname(__file__)
PROJECT_PATH = os.path.join( SETTINGS_DIR, os.pardir)
PROJECT_PATH = os.path.abspath(PROJECT_PATH)

TEMPLATE_PATH = os.path.join( PROJECT_PATH, 'templates')

BASE_DIR = os.path.dirname(os.path.dirname(__file__))



SECRET_KEY = 't0qwy81#5-jd(wtxqp$6_p%@l@lthq5qyb-35vyp=g+h!k+h+n'


DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'django.contrib.admindocs',
    'rango',

)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'RangoTango.urls'

WSGI_APPLICATION = 'RangoTango.wsgi.application'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

TEMPLATE_DIR = (
    TEMPLATE_PATH,
)


LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_URL = '/static/'

错误:

请求方法:GET 请求网址:127-0-0-1 Django版本:1.6.5 例外类型:TemplateDoesNotExist 例外价值:
/rango/index.html 例外位置:/ Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django /

1 个答案:

答案 0 :(得分:0)

我必须将文件夹移动到我的app文件夹才能使其正常工作