我正在用Python构建一个网站(使用heroku),我想创建一个“最新的提交”部分。也就是说,当我在我的Python应用程序中创建一个新的@app.route(blah)
时,我想要一个到新页面的链接,显示在我的主页上的“最新提交”部分下。显示创建新网页的链接
这可能吗?
编辑:这里是我的代码
import os
import json
from flask import Flask, render_template, url_for
from werkzeug.routing import Map, Rule, NotFound, RequestRedirect, BaseConverter
app = Flask(__name__)
@app.route('/')
def index():
return render_template('welcome.html')
@app.route('/about', endpoint='about')
def index():
return render_template('about.html')
@app.route('/contact', endpoint='contact')
def index():
return render_template('contact.html')
@app.route('/all-links', endpoint='all-links')
def all_links():
links = []
for rule in app.url_map.iter_rules():
url = url_for(rule.endpoint)
links.append((url, rule.endpoint))
return render_template('all_links.html', links=links)
if __name__ == '__main__':
# Bind to PORT if defined, otherwise default to 5000.
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)
和所有的应用程序的路线都存储在app.url_map
的all_links.html文件
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>links</title>
</head>
<body>
<ul>
{% for url, endpoint in links %}
<li><a href="{{ url }}">{{ endpoint }}</a></li>
{% endfor %}
</ul>
</body>
</html>
'这是可能的'有?如果你发布了一些你已经尝试过的代码,你可能会得到更好的回应。 – John
在这一点上,我正在寻找更多的方向,而不是实际的“这是答案”的答案。我可以在烧瓶中完全做到这一点吗?我的主要app.py文件中是否使用了python编码和烧瓶编码的组合? –
Flask *是Python ;-) –