Forums

How to correctly use render_template here?

I have a template and its location is like: index/login/index.html , but it depends on several files in the index directory to render completely. I used: render_template('index/login/index.html',newsession=1)

But it isn't rendering the page completely as most likely Flask is not accessing those files in index directory. How to do it? It seems to work on my home computer.

Hi,

Have you tried using a fully qualified filename: i.e. /home/zerop/whatever/index/login/index.html ?

Thanks, Robert

Flask searches in the templates directory. The full path is /home/zerop/templates/index/login/index.html. I just need to proved the relative path and it will work. I want to make it clear that the file "index.html" does load but various CSS fies in the index directory are not loading so the page is not rendering completely.

Now I think that it is because there is no handler in my web app to serve those files. For ex: if the browiser asks for http://zerop.pythonanywhere.com/templates/wp-content/style.css then there is no handler in my webapp to serve those files. Now i can't manually do this for all files, so what can be a way to create a default behaviour?

I found the solution myself. I am posting it here just in case somebody needs it.

I went to the Web tab in Dashboard and saw the Static box which I missed before :/

I entered the path of all static folders in there: For ex wp-content contains many stylesheets so I put in:

URL: /wp-content/ PATH: /home/zerop/api/templates/index/wp-content/

and so on for all folders and it worked like a charm.