1
私はHerokuで休憩サービスを開くためのdjangorestframeworkをインストールしました。HerokuのTemplateDoesNotExist Django Rest Frameworkを使用
私はローカル環境でWebサイトを開くと、私は次のようなメッセージがあります
TemplateDoesNotExist at/
rest_framework/api.html
Request Method: GET
Request URL: http://192.168.56.102:8000/
Django Version: 1.9.2
Exception Type: TemplateDoesNotExist
Exception Value:
rest_framework/api.html
Exception Location: /home/_ws_/rest/gps2/venv/lib/python2.7/site-packages/django/template/loader.py in get_template, line 43
Python Executable: /home/_ws_/rest/gps2/venv/bin/python
Python Version: 2.7.5
Python Path:
['/home/_ws_/rest/gps2',
'/home/_ws_/rest/gps2/venv/lib64/python27.zip',
'/home/_ws_/rest/gps2/venv/lib64/python2.7',
'/home/_ws_/rest/gps2/venv/lib64/python2.7/plat-linux2',
'/home/_ws_/rest/gps2/venv/lib64/python2.7/lib-tk',
'/home/_ws_/rest/gps2/venv/lib64/python2.7/lib-old',
'/home/_ws_/rest/gps2/venv/lib64/python2.7/lib-dynload',
'/usr/lib64/python2.7',
'/usr/lib/python2.7',
'/home/_ws_/rest/gps2/venv/lib/python2.7/site-packages']
Server time: Fri, 22 Apr 2016 14:53:25 +0000
私は何をすべきか?おそらくこれはsettings.pyファイルに関連するものです。
Mineは公式のもので、データベース(この例では空)とトラックプロジェクトを追加したものです。
import os
import dj_database_url
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ""
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'tracks',
)
MIDDLEWARE_CLASSES = (
'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',
)
ROOT_URLCONF = 'gps2.urls'
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',
],
'debug': DEBUG,
},
},
)
WSGI_APPLICATION = 'gps2.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': '',
'USER': '',
'HOST': '',
'PASSWORD': '',
}
}
AUTH_PASSWORD_VALIDATORS = (
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
)
# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Update database configuration with $DATABASE_URL.
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Allow all host headers
ALLOWED_HOSTS = ['*']
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = [
os.path.join(PROJECT_ROOT, 'static'),
]
# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
私はまた、メッセージいます
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.filesystem.Loader: /home/_ws_/rest/gps2/templates/rest_framework/api.html (Source does not exist)
django.template.loaders.app_directories.Loader: /home/_ws_/rest/gps2/venv/lib/python2.7/site-packages/django/contrib/admin/templates/rest_framework/api.html (Source does not exist)
django.template.loaders.app_directories.Loader: /home/_ws_/rest/gps2/venv/lib/python2.7/site-packages/django/contrib/auth/templates/rest_framework/api.html (Source does not exist)
ファイルが実際にあります:
/home/_ws_/rest/gps2/venv/lib/python2.7/site-packages/rest_framework/templates/rest_framework/api.html
どのように私は、このディレクトリを得ることができますか?
あなたはありがとうございます。 – pateto777