0
我正在使用燒瓶並且有一個包含從表中獲取的用戶名(user.html)的html頁面現在,我怎樣才能通過單擊每個用戶來查看更多詳細信息(哪個路由到配置文件)? 我不使用登錄應用程序,所以我不想用摹通過主鍵在燒瓶中獲取用戶
app.py
# am I doing it right?
@app.route('/profile/<int:id>')
def profile(id=None):
detail = Contacts.query.get(id)
return render_template('profile.html', detail= detail , id=id)
user.html
{% extends "layout.html" %}
{% block content %}
<h2>show user</h2>
{% for contact in contact %}
# I got error when I click on each user name to see their 'profile'
#I guess because of id How can Solve it?
#error BuildError: ('profile', {}, None)
<strong>name:</strong><a href={{url_for('profile')}}>
{{ contact.name}}</a><br>
{% endfor %}
{% endblock %}
profile.html
{% extends "layout.html" %}
{% block content %}
<h2>show user profile</h2>
# how can I make it specific for each row of table(each user)?
{% for detail in Contacts %}
<strong>name:</strong> {{ detail.name}} <br>
<strong>email:</strong> {{ detail.email }} <br>
<strong>age:</strong> {{ detail.age}} <br>
<br>
{% endfor %}
{% endblock %}
model.py
class Contacts(db.Model):
__tablename__ = "Contacts"
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(50))
email = db.Column(db.String(50))
age = db.Column(db.Integer)
submit = SubmitField("Submit")
@琳達對不起。我更新了我的答案,以考慮這一點。希望能幫助到你。 – Jivan 2014-12-27 19:49:19
謝謝你的幫助:) @Jivan – Linda 2014-12-27 19:52:18