1
我不知道什麼怎麼回事錯了...我得到這個錯誤:瓶SQLAlchemy的InterfaceError
InterfaceError: (InterfaceError) Error binding parameter 0 - probably unsupported type. u'SELECT contact.id AS contact_id, contact.surname AS contact_surname, contact.firstname AS contact_firstname, contact.email AS contact_email, contact.mobile AS contact_mobile, contact.work_location AS contact_work_location \nFROM contact \nWHERE contact.id = ?' ([1],)
我的方法:
@app.route('/contacts/<int:contact_id>', methods=['GET'])
def contact_detail(contact_id):
if request.method == 'GET':
db.session.query(Contact).filter_by(id=[contact_id]).all()
return render_template('modcontact.html', title = 'Contact Detail')
我的模型:
class Contact(db.Model):
id = db.Column(db.Integer, primary_key = True)
surname = db.Column(db.String(100))
firstname = db.Column(db.String(100))
email = db.Column(db.String(100))
mobile = db.Column(db.String(20))
work_location = db.Column(db.String(100))
#user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
def __repr__(self):
return '<Contact %r>' % (self.surname)
模板:
{% extends "base.html" %}
{% block content %}
<h1>List of contacts</h1>
<ul class=contacts>
{% for contacts in contacts %}
<li><h3>
<a href="{{ url_for('contact_detail',contact_id=contacts.id)}}">
{{ contacts.surname }}, {{ contacts.firstname }}
</a>
</h3></li>
{% else %}
<li><em>No contacts available</em></li>
{% endfor %}
</ul>
<a href="/addcontact/">Add a new contact</a>
{% endblock %}