2

I read the document about django tutorial. Now I want to read my html and display it. So I start a project and start a app myapp_page. The folder structure is blow.

enter image description here

I render my html file in the views. There is "Hello world" in this html file.

enter image description here

I set the path in the urls.py.

enter image description here

And I add the folder path in the settings.py.

enter image description here

But the html didn't show in the 127.0.0.1:8000/myapp_page/

How to display my custom html file?

How does the django manage the path?

I am confuse.

1
  • I know it's been 5 years later but remember to add "return" to your render line in views.py otherwise you will get "ValueError at '<path>'. So the line should be "return render(request, 'myapp_page.html')" Commented Sep 17 at 9:14

1 Answer 1

4

Rename your template directory to templates change it in settings.py too, this is optional.

In views.py change the line to return render(request, 'myapp_page.html')

Note the return function added.

You do not need to specify templates/ dir again because Django knows it and starts looking from its (directory's root)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, if I want to define the "template" folder, is it possible?
Yes, you can change it to template. I suggested it because docs refer them and by default Django in apps sees templates directory. If the solution works please consider accepting it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.