正在开发一个角度前端和Django后端应用程序。我不知道我哪里出错了但Django似乎找不到模板并显示模板不存在消息。项目目录看起来像这样。后端服务器位于“django项目”文件夹
base.py(设置)
import environ
project_root = environ.Path(__file__) - 3
env = environ.Env(DEBUG=(bool, False),)
CURRENT_ENV = 'dev' # 'dev' is the default environment
# read the .env file associated with the settings that're loaded
env.read_env('./mysite/{}.env'.format(CURRENT_ENV))
#Database
DATABASES = {
'default': env.db()
}
SECRET_KEY = env('SECRET_KEY')
DEBUG = env('DEBUG')
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# Django Packages
'rest_framework',
'mysite.applications.games',
]
ROOT_URLCONF = 'mysite.urls'
STATIC_URL = '/static/'
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
STATICFILES_DIRS = [
env('FRONTEND_ROOT')
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [env('FRONTEND_ROOT')],
'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',
],
},
},
]
环境变量文件(dev.env)
DATABASE_URL=sqlite:///mysite.db
DEBUG=True
FRONTEND_ROOT= ('C:/downloads/mysite/frontend/')
SECRET_KEY= '##########################'
urls.py
from django.contrib import admin
from django.conf.urls import include, url
from mysite.applications.api.v1.routes import api_router
from django.views.generic import TemplateView
urlpatterns = [
url(r'^admin/', admin.site.urls),
# Web App Entry
url(r'^$', TemplateView.as_view(template_name="/app/index.html"), name='index'),
]
答案 0 :(得分:0)
我将模板DIRS设置更改为指向'C:/ downloads / mysite / frontend /',并且模板名称指向“/app/index.html".app是前端内的文件夹。