Forums

Template working at root, but not other pages

Hi,

I am trying to use a template with a d3.js script on my page. When served from the root of the page, the template works perfectly, the graph is served by d3.js. The template (for purposes of setting up, I want to use my own data/details later) is basically this: http://bl.ocks.org/mbostock/4062045#miserables.json

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

However, when trying to serve it from another page, the script no longer works (i.e. the page displayed is blank, but has the desired title, so the template obviously is found/read).

@app.route('/about/')
def about():
    return render_template('d3example.html') # same html as index.html

The ds3.js file is located in a "static" folder, whereas the html file(s) are located in a "templates" folder, both located inside "mysite" folder. The static files path has been set up in the "web" tab.

Did you import it?

from flask import render_template

Yes, of course. As stated, in first case, it renders correctly, whereas in second it sees the page title correctly, just does not display the data produced by the js script.

Whewww, solved. For future reference of anyone interested:

In pages other than the root, you cannot just use the relative /static/file path - need to do it by absolute path using {{ url_for('static', filename=filename) }}