EDIT: I found the problem, I simply had a mistyped folder! Anyhow, I thought this would still be useful code if anyone needs it.
Let's say I have a file called test.html and I want it to be returned when I load it on my Flask server, but I don't want to write this for every file I have:
@app.route("/test.html")
def atestfile(name=None):
return open("/home/pi/test/test.html", "r").read()
So I thought something like this would work:
from flask import Flask
app = Flask(__name__)
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catchall(path):
home = "/home/pi/test/"
url = home + str(path)
page = open(url, "r").read()
return page
if __name__ == "__main__":
app.run('0.0.0.0')
I know the def catchall(path):
part could be shortened to one line but I wanted to keep it simple to spot any errors. I get a 500 Internal Server Error
on the web page and no explanation for why in my terminal on my server (Raspbian).
So how could I do something like this?