Reputation: 3241
I've just started with django. I'm finding so many question about this problem, but I see most of all are outdated. I guess something has changed between 2.1 and 2.2.
This is my tree
.
|____posts
| |____migrations
| | |______init__.py
| |____models.py
| |______init__.py
| |____apps.py
| |____admin.py
| |____templates
| | |____posts
| | | |____index.html
| |____tests.py
| |____urls.py
| |____views.py
|____django_project
| |______init__.py
| |____settings.py
| |____urls.py
| |____wsgi.py
|____manage.py
This is the content of posts/views.py
def index(req):
return render(req, 'posts/index.html')
When I try to access http://127.0.0.1:8000/posts/
I get the error
TemplateDoesNotExist at /posts/
To me it looks like I've done exactly what https://docs.djangoproject.com/en/2.2/topics/templates/ says. What am I missing?
This is the content of settings.py https://pastebin.com/qkGhLtsW
Upvotes: 0
Views: 732
Reputation: 199
Within your main settings file you will need to find the list variable
INSTALLED_APPS
Add to the top of the list
'posts',
Doing this tells your Django system that there is an app that has been created called posts. It will then search within posts for templates and you will begin to see your HTML files
Upvotes: 0
Reputation: 11
Use 'DIRS': ['posts/templates'],
because your templates folder is inside the posts folder...
Upvotes: 0
Reputation: 600059
Your template is in an application templates directory, but you have not added that application to INSTALLED_APPS, so Django does not know to look there.
Upvotes: 2