Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
471 views
Welcome To Ask or Share your Answers For Others

1 Answer

You do not need the templates/ in your template path, since your telling Django to look inside the dir already through your settings. Also, context_instance=RequestContext(request) is deprecated, you just need to return a dict containing your context (an empty dict in your case?):

def render_landing_page(request, template="index.html"):
    return render(request, template, {})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...