Forums

jinja2.exceptions.TemplateNotFound: home.html

I went back to an old account to boot up a website I made a while back. I am not having an issue where the web app can not find the ''home.html' file even though it is just in my templates folder. Is anyone from pythonanywhere able to look at mysite or do you need me to post my code for help?

Sure, we can take a look at your files using our admin interface if you give us explicit permission (and your post above would count as permission :-)

However, taking a look at your error logs it looks to me like you have worked out what the issue was, and it's finding the template now. Is that correct?

Yes I did fix it. Thank you for you for looking into it though, you guys are awesome!

Glad you got that fixed!

hey I have the same issue!!

jinja2.exceptions.TemplateNotFound: login.html

even though my templates folder consists of login.html

can someone help me out!

Maybe try the absolute path to the template.

I have the same problem and i have it was working at the start and the wen i add exter code me (‘/‘) page said jinja2.exceptions.templatenotfound: so i did what you said and i made it the absolute path and it still does work can you help me find the right answer as I’ve look all over the internet and cant find the answer this is my code

Define a route for the dashboard page

@app.route('/') def dashboard(): return render_template('/home/Edpdash/XXXX/templates/dash_board.html') What am i doing wrong if it worked at the start with Return render_template(‘dash_board.html’)

Can you please look at my code and tell me what i have dont wrong

This is my error report

2023-03-05 21:44:03,551: Exception on / [GET] Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2077, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1525, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1523, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1509, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) File "/home/Edpdash/Edp/website.py", line 24, in dashboard return render_template('/home/Edpdash/XXX/templates/dash_board.html') File "/usr/local/lib/python3.10/site-packages/flask/templating.py", line 149, in render_template ctx.app.jinja_env.get_or_select_template(template_name_or_list), File "/home/Edpdash/.local/lib/python3.10/site-packages/jinja2/environment.py", line 1068, in get_or_select_template return self.get_template(template_name_or_list, parent, globals) File "/home/Edpdash/.local/lib/python3.10/site-packages/jinja2/environment.py", line 997, in get_template return self._load_template(name, globals) File "/home/Edpdash/.local/lib/python3.10/site-packages/jinja2/environment.py", line 958, in _load_template template = self.loader.load(self, name, self.make_globals(globals)) File "/home/Edpdash/.local/lib/python3.10/site-packages/jinja2/loaders.py", line 125, in load source, filename, uptodate = self.get_source(environment, name) File "/usr/local/lib/python3.10/site-packages/flask/templating.py", line 59, in get_source return self._get_source_fast(environment, template) File "/usr/local/lib/python3.10/site-packages/flask/templating.py", line 95, in _get_source_fast raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: /home/Edpdash/XXXX/templates/dash_board.html

render_template does not take the path to the template as its argument. It takes the template name: https://flask.palletsprojects.com/en/2.2.x/api/#flask.render_template.

The place where you need to use an absolute path is where you define your template directory by specifying the template_folder: https://flask.palletsprojects.com/en/2.2.x/api/#application-object