Created
December 1, 2015 08:29
-
-
Save pawl/9e12f0f8d0d482ece2a7 to your computer and use it in GitHub Desktop.
trying to reproduce the issue here: https://github.com/coleifer/wtf-peewee/pull/30
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from peewee import Model, CharField, SqliteDatabase | |
from wtforms import validators | |
from wtfpeewee.orm import model_form | |
from flask import Flask, abort, request, flash, render_template | |
app = Flask(__name__) | |
app.config['SECRET_KEY'] = '123456790' | |
db = SqliteDatabase('test.sqlite', check_same_thread=False) | |
class BaseModel(Model): | |
class Meta: | |
database = db | |
class Blog(BaseModel): | |
name = CharField() | |
def __unicode__(self): | |
return self.name | |
BlogForm = model_form(Blog, field_args={ | |
'name': dict(validators=[validators.Optional()]), | |
}) | |
@app.route('/entries/<int:entry_id>/', methods=['GET', 'POST']) | |
def edit_entry(entry_id): | |
try: | |
blog = Blog.get(id=entry_id) | |
except Blog.DoesNotExist: | |
abort(404) | |
if request.method == 'POST': | |
form = BlogForm(request.form, obj=blog) | |
if form.validate(): | |
form.populate_obj(blog) | |
blog.save() | |
flash('Your blog has been saved') | |
else: | |
form = BlogForm(obj=blog) | |
return render_template('untitled.html', form=form, blog=blog) | |
if __name__ == '__main__': | |
try: | |
Blog.create_table() | |
Blog.create(id=1, name="test") | |
except: | |
pass | |
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>title</title> | |
</head> | |
<body> | |
{% block body %} | |
<form method="post" action=""> | |
{% for field in form %} | |
<p>{{ field.label }} {{ field }}</p> | |
{% endfor %} | |
<p><button type="submit">Submit</button></p> | |
</form> | |
{% endblock %} | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment