0
我迷失在python和flask中,因爲我不明白路由結構如何在HTML頁面之間導航。hwo我可以使用正確的路由來顯示Flask的HTML頁面嗎?
部署到Heroku的我的結構是:
/my_app_name/
app.py
config.py
drivers.html
Procfile
requirements.txt
的app.py文件是:
import os
from flask import Flask, render_template, request, url_for
from flask.ext.sqlalchemy import SQLAlchemy
import json
app = Flask(__name__)
db = SQLAlchemy(app)
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello World from Python!'
@app.route('/')
def drivers():
drivers = db.drivers.select()
return render_template('drivers.html')
#return HttpResponse('/drivers.html', json.dumps(result), content_type='application/json')
if __name__ == '__main__':
app.run(debug=True)
config.py是:
SQLALCHEMY_DATABASE_URI = 'heroku_database_uri_string) #connection is OK, no problem here
drivers.html是:
{% block body %}
<ul>
{% for driver in drivers %}
<li><h2>{{ driver.driver_name }}</h2>
</ul>
{% endblock %}
當我瀏覽到myapp.heroku.com/我「從pyhton世界你好」得很好的,但是當我瀏覽到myapp.heroku.com/drivers.html
,我收到了「404」的錯誤。
所以,2個問題:
1)爲什麼404?哪裏不對?
2)我認爲是,但整個結構是否有缺陷?
非常感謝!
感謝這部分幫助我。我已閱讀燒瓶文檔,但尚未完全理解它們。毫無疑問,我會回來尋求更多幫助! – user1903663