0

I tried doing this: enter image description here

from django.http import HttpResponse
from django.shortcuts import render

def home(request):
    return render(request, 'templates/index.html')

But my page says that TemplateDoesNotExist.

enter image description here

What should I do?

Zedd
  • 2,069
  • 2
  • 15
  • 35
  • Does this answer your question? [Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/contacts/contact.html](https://stackoverflow.com/questions/60938227/page-not-found-404-request-methodget-request-urlhttp-127-0-0-18000-cont) – Ahmed I. Elsayed Apr 04 '20 at 03:33

3 Answers3

1

Create a folder 'justcolor' under templates directory and save index.html in it. change path to 'justcolor/index.html'. return render(request, 'justcolor/index.html')

Neeraj
  • 783
  • 5
  • 8
  • `templates` better be a subdir of the app, not of the project. And I think the template path is case sensitive too, so it's `justColor/index.html` – Niloct Apr 04 '20 at 03:34
  • I don't have an app for this project. This simply is the subdirectory for my project – Zedd Apr 04 '20 at 03:40
  • I got the answer. Thanks. I was able to solve my own problem on my own. In fact, I posted the right answer for this question here. But thanks anyways. – Zedd Apr 04 '20 at 04:00
0

Make sure you have configured urls.py and views.py correctly.

This question is already answered here :Django TemplateDoesNotExist?

  • I got the answer. Thanks. I was able to solve my own problem on my own. In fact, I posted the right answer for this question here. But thanks anyways. – Zedd Apr 04 '20 at 04:00
0

Make a templates\justColor subdirectory template inside your justColor folder and move index.html to there. Then as @Neeraj said you can change render call to render(request, 'justColor/index.html').

(Although you should read this part of the django tutorial which will help you more than any trial-and-error in this subject: https://docs.djangoproject.com/en/3.0/intro/tutorial03/)

Niloct
  • 9,491
  • 3
  • 44
  • 57
  • I got the answer. Thanks. I was able to solve my own problem on my own. In fact, I posted the right answer for this question here. But thanks anyways. – Zedd Apr 04 '20 at 04:00
  • @ZeddrixFabian you've probably changed the `DIRS` variable on `settings.py` to add the template directory right ? My answer was a secondary option when you enable apps on the settings file. – Niloct Apr 05 '20 at 03:50