我经历了许多教程和一切工作。但是我开始了自己的网站,只找到404错误。错误404与静态页面(烧瓶框架)
我下载了一个HTML模板,并设法将文件从Github克隆到PythonAnywhere。现在我的文件结构是: Screenshot
Flask_app.py代码:
from flask import Flask
# set the project root directory as the static folder, you can set others.
app = Flask(flask_app, static_url_path='/home/dubspher/mysite')
app = Flask(__name__)
@app.route('/home/dubspher/mysite/')
def static_file(path):
return app.send_static_file(index.html)
if __name__ == "__main__":
app.run()
我应该创建模板,另一个网站,并使用render_template或有一个办法可以要求一个静态页面烧瓶?
到目前为止,我尝试了许多代码,但我不知道需要什么来与static_url_path做
HTML:https://www.pythonanywhere.com/user/dubspher/shares/db715c9b9d7c43b7beb4245af23fb56c/
让我知道,如果我需要增加更多的信息。
你看看https://stackoverflow.com/questions/20646822/how-to-serve-static-files-in-flask – clockwatcher
是的这段代码直接来自这个页面。 –
@ app.route定义了请求中瓶子将要查找的url路径。那么你要求什么网址?您必须要求http://yoursite.com/home/dubspher/mysite/才能打到您的索引页面。这是你要求的还是你要求http://yoursite.com?如果是后者,则需要将路由定义为@ app.root('/')。此外,index.html需要在引号中。 – clockwatcher