Ask coding questions

← Back to all posts
Template Not Found!
LohBoon

I was to run the Flask server to view the login and register html, but the displaty shown "Internal Server Error".

How to resolve it and why it happen?

Thank you.

Answered by 19wintersp [earned 5 cycles]
View Answer
Voters
DavidWallington
LohBoon
Comments
hotnewtop
19wintersp

I think the issue is that you are trying to render "index.html" (main.py:14) but that file doesn't exist.

Edit: apparently I wasn't clear enough. The file "index.html" does not exist in your template directory for the app, which is undefined. You should modify your template folder to be "flask-tutorial/flaskr/templates", by modifying main.py:4 as follows:

Note that if you are trying to render "blog/index.html" as the homepage, you must also update main.py:14 with that.

RYANTADIPARTHI

@19wintersp yes it does.

19wintersp

@RYANTADIPARTHI Where is it?

RYANTADIPARTHI

@19wintersp look properly. not just the surface.

19wintersp

@RYANTADIPARTHI The only "index.html" is under "blog". What on earth do you mean by "the surface"?

RYANTADIPARTHI

@19wintersp exactly.

19wintersp

@RYANTADIPARTHI

exactly.

Is this supposed to be profound? It makes no sense.

RYANTADIPARTHI

@19wintersp you found the file.

19wintersp

@RYANTADIPARTHI And? If that's what they want to render, they need to specify their template directory.

RYANTADIPARTHI

@19wintersp yes, but you should have made your first comment clear. Instead of straightup saying no such file as index.html.

19wintersp

@RYANTADIPARTHI Well, that is the issue. They do not have an "index.html" file in their template directory ("."), and so either need to create one or modify it. I will update my answer if this isn't clear enough.

RYANTADIPARTHI

@19wintersp yes. do update it.

LohBoon

@19wintersp I have amended by deleted the index.html, but still an internal error. Please help! Thank you.

19wintersp

@LohBoon What did you do?

LohBoon

@19wintersp the site indicated tryimport(module_name)

LohBoon

@19wintersp flask.cli.NoAppException: Could not import "flaskr.flaskr".

19wintersp

@LohBoon You've deleted "main.py", or cleared it anyway.

LohBoon

@19wintersp I have added you, please help me to amend the code. Thank you.

LohBoon

@19wintersp yes deleted

RYANTADIPARTHI

your error is probably because you should name your folder templates instead of flaskr. And then, render it from there, with the proper file directory.

LohBoon

@RYANTADIPARTHI I have deleted the index.html, so will in render to base.html? flask.cli.NoAppException: Could not import "flaskr.flaskr".

19wintersp

@LohBoon No! Deleting it won't make it render a different file! You need to specify which file you want to render in your code.