0

I have a index.html file, which has the absolute path 'c:\project\web\frontend\index.html'

I am trying to return it using the following function

@webserver.route('/')
def home()
     return webserver.send_static_file(path)

I have verified that the path is correct by accessing it directly in the browser.

I have tried to replace '\' with '/' without any luck.

It is running on a windows machine.

2 Answers 2

1

If you look at flask's documentation for send_static_file. You'll see that it says that it's used internally by flask framework to send a file to the browser. If you want to render an html, it's common to use render_template. You need to make sure that your index.html is in a folder called templates first. So I would do the following:

@webserver.route('/')
def home()
     return flask.render_template('index.html') 
Sign up to request clarification or add additional context in comments.

1 Comment

yes, but since this is a static HTML, I though I could use send_static_file. The issue was that I did not see that the file must be under a predefined "static folder". Once I defined the the path to be static in the app definition, it worked.
1

I had to define the path to be the static_folder, when creating the flask object. Once I defined the folder to be static, the html page was served.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.