You're trying to do requests to test.html
, but that route does not exist, you have only defined the /
route in your Python code which renders index.html
template.
If you want the user to access arbitrary templates (e.g. 127.0.0.1:5000/templates/my-template.html
), you can write the following route:
@app.route('/templates/<template_name>')
def view_template(template_name):
return render_template(template_name)
Once you've defined that route, the request to /templates/test.html
should be successful:
httpRequest.open('GET', '/templates/test.html', true)
Flask looks for the specified template in templates
folder by default when you call render_template
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…