2017-05-03 2 views
-2

Ich muss alle Daten von der Tabelle auf HTML-Seite übertragen. In der SQLAlchemy wird es so ähnlich sein.Gibt es eine Möglichkeit, query.all() in peewee abzufragen?

class Author(db.Model): 
    id = db.Column(db.Integer, primary_key=True) 
    first = db.Column(db.String(80)) 
    last = db.Column(db.String(80)) 


@app.route('/authors') 
def get_authors(): 
    authors = Author.query.all() 
    # Serialize the queryset 
    result = authors_schema.dump(authors) 
    return jsonify({'authors': result.data}) 

Gibt es eine etwas wie Autoren = Author.query.all() im Peewee?

+0

http://docs.peewee-orm.com/de/latest/peewee/api.html#Model.select –

Antwort

1

so mache ich das.

@app.route('/authors') 
def get_authors(): 
    authors = Author.select() 
    return render_template('aurhors.html', authors=authors) 

Und in HTML etwas wie das.

{% for a in authors %} 
<p>{{a.author_name}}</p> 
{% endfor %} 

Ich nur am Anfang des Studiums Python, so danke für Hilfe.

Verwandte Themen