Non the the solutions already posted seem to be working for me.
This is my project directory.
.
|-- 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
This is my settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(os.path.dirname(__file__), '../static/'),
)
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, '../templates'),
)
I've also tried,
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
This is my views.py
def render_landing_page(request, template="templates/index.html"):
return render(request, template, context_instance=RequestContext(request))
And this is my urls.py
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', views.render_landing_page),
]
At 127.0.0.1:8000/ I get a "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
But, when I go to 127.0.0.1:8000/static/index.html. The page is rendered.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…