kristheman
kristheman

Reputation: 89

Flask rendering templates from another folder

I have a simple flask app with only an index.html page (so far), it's located in a folder with a bunch of javascript and CSS, which makes it a bit difficult to render.

I tried listing the file path for my HTML, however, it gives an internal server error, when I open the browser. Should I instead declare the path as a variable and pass that in?

I'm on Linux Ubuntu 16.04 btw.

here is my sample code:

from flask import Flask, render_template
app = Flask(__name__)


@app.route("/")
@app.route("/home")
def home():
    return render_template('/frontend/index.html')

here is how my directory is listed

--flaskwebsite
----routes.py
----routes.pyc
----templates
------frontend(other folders, javascript files etc)
------index.html

Upvotes: 1

Views: 3096

Answers (1)

Kevin Hernandez
Kevin Hernandez

Reputation: 1400

If Im seeing your folder structure correctly.

'templates/frontend/index.html'

Also you should have a separate template folder and a separate folder for static files such as css, js, pictures, and fonts.

Upvotes: 3

Related Questions