[英]Template and static files setup with Django 1.8
我的模板無法正常工作。 總體而言,非常不確定如何在我的項目目錄中設置靜態文件和模板。
作為最佳實踐,我應該在開發時將模板放在app文件夾中,還是將靜態文件放在app文件夾中?
這是輸出:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/Users/username/Dev/test_dev_01/projects/test/main/templates/main/templates/index.html (File does not exist)
/Users/username/Dev/test_dev_01/lib/python3.4/site-packages/tinymce/templates/main/templates/index.html (File does not exist)
/Users/username/Dev/test_dev_01/lib/python3.4/site-packages/mce_filebrowser/templates/main/templates/index.html (File does not exist)
/Users/username/Dev/test_dev_01/lib/python3.4/site-packages/django/contrib/auth/templates/main/templates/index.html (File does not exist)
/Users/username/Dev/test_dev_01/lib/python3.4/site-packages/django/contrib/sitemaps/templates/main/templates/index.html (File does not exist)
/Users/username/Dev/test_dev_01/lib/python3.4/site-packages/mezzanine/conf/templates/main/templates/index.html (File does not exist)
/Users/username/Dev/test_dev_01/lib/python3.4/site-packages/mezzanine/core/templates/main/templates/index.html (File does not exist)
/Users/username/Dev/test_dev_01/lib/python3.4/site-packages/mezzanine/generic/templates/main/templates/index.html (File does not exist)
/Users/username/Dev/test_dev_01/lib/python3.4/site-packages/mezzanine/pages/templates/main/templates/index.html (File does not exist)
/Users/username/Dev/test_dev_01/lib/python3.4/site-packages/mezzanine/blog/templates/main/templates/index.html (File does not exist)
/Users/username/Dev/test_dev_01/lib/python3.4/site-packages/mezzanine/forms/templates/main/templates/index.html (File does not exist)
/Users/username/Dev/test_dev_01/lib/python3.4/site-packages/mezzanine/galleries/templates/main/templates/index.html (File does not exist)
/Users/username/Dev/test_dev_01/lib/python3.4/site-packages/mezzanine/accounts/templates/main/templates/index.html (File does not exist)
/Users/username/Dev/test_dev_01/lib/python3.4/site-packages/avatar/templates/main/templates/index.html (File does not exist)
/Users/username/Dev/test_dev_01/lib/python3.4/site-packages/filebrowser_safe/templates/main/templates/index.html (File does not exist)
/Users/username/Dev/test_dev_01/lib/python3.4/site-packages/grappelli_safe/templates/main/templates/index.html (File does not exist)
/Users/username/Dev/test_dev_01/lib/python3.4/site-packages/django/contrib/admin/templates/main/templates/index.html (File does not exist)
/Users/username/Dev/test_dev_01/lib/python3.4/site-packages/django_comments/templates/main/templates/index.html (File does not exist)
urls.py:
url(r"^$", "main.views.home", name="home"),
views.py:
def home(request):
return render(request, "main/templates/index.html", context)
settings.py:
PROJECT_APP_PATH = os.path.dirname(os.path.abspath(__file__))
PROJECT_APP = os.path.basename(PROJECT_APP_PATH)
PROJECT_ROOT = BASE_DIR = os.path.dirname(PROJECT_APP_PATH)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
#os.path.join(PROJECT_ROOT, 'templates')
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.static",
"django.core.context_processors.media",
"django.core.context_processors.request",
"django.core.context_processors.tz",
"mezzanine.conf.context_processors.settings",
"mezzanine.pages.context_processors.page",
"main.context_processors.global_settings",
],
},
},
]
這可能是什么原因? 我不知道。
我只是在推斷這是因為您尚未提供以下信息:
main
index.html
確實位於: /Users/username/Dev/test_dev_01/projects/test/main/templates/index.html
如果我的假設是正確的,則您對render的調用應為:
def home(request):
return render(request, "index.html", context)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.