[code python
from app import db
class User(db.Model):
id = db.Column(db.Integer, primary_key = True)
nickname = db.Column(db.String(64), unique = True)
password = db.Column(db.String(64))
def __repr__(self):
return ‘<User %r>’ % (self.nickname)
]
forms
__author__ = 'qq' from flask.ext.wtf import Form from wtforms import StringField, BooleanField, PasswordField, validators from wtforms.validators import DataRequired class RegForm(Form): nickname = StringField('user', validators = [DataRequired()]) password = StringField('password', validators = [DataRequired()])
views
from flask import render_template, flash, redirect, request from app import app, db from forms import LoginForm, RegForm from models import User @app.route('/reg', methods=['GET','POST']) def reg(): form = RegForm(request.form) if form.validate_on_submit(): u = User(nickname=form.nickname.data, password=form.password.data) db.session.add(u) db.session.commit() flash('tnx') else: flash('BAD validate') return render_template("reg.html", form = form)
reg gtml
{% block content %}
<h1>Reg</h1>
<form action="" method="post" name="reg">
<p>{{ form.nickname }} username</p>
<p>{{ form.password }} pass</p>
<p><input type="submit" value="reg"></p>
</form>
{% endblock %}
Не получается записать данные с формы в базу данных ( просто ничего не происходит, направьте на путь истинный