【发布时间】:2016-08-27 03:18:05
【问题描述】:
不是已经发布的解决方案似乎对我有用。
这是我的项目目录。
.
|-- auto
| |-- admin.py
| |-- apps.py
| |-- __init__.py
| |-- migrations
| |-- models.py
| |-- views.py
|-- db.sqlite3
|-- manage.py
|-- mysite
| |-- __init__.py
| |-- settings.py
| |-- test.py
| |-- urls.py
| |-- wsgi.py
|-- static
| |-- index.html
`-- templates
`-- index.html
这是我的 settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(os.path.dirname(__file__), '../static/'),
)
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, '../templates'),
)
我也试过了,
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
这是我的观点.py
def render_landing_page(request, template="templates/index.html"):
return render(request, template, context_instance=RequestContext(request))
这是我的 urls.py
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', views.render_landing_page),
]
在 127.0.0.1:8000/ 我得到一个“TemplateDoesNotExist at /”
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.9.4
Exception Type: TemplateDoesNotExist
Exception Value:
templates/index.html
但是,当我转到 127.0.0.1:8000/static/index.html 时。页面被渲染。
【问题讨论】:
-
TEMPLATE_DIRS自 Django 1.8 起已弃用。请改用docs.djangoproject.com/en/1.9/ref/settings/#templates。