Я работаю с флягой и располагаю html-страницей, содержащей имя пользователя (user.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")
@ Linda да, простите об этом. Я обновил свой ответ, чтобы принять это во внимание. Надеюсь, поможет. – Jivan
Thanx So much За вашу помощь :) @ Jivan – Linda