class IntegrityError(DatabaseError):
"""Wraps a DB-API IntegrityError."""
class DatabaseError(DBAPIError):
"""Wraps a DB-API DatabaseError."""
try:
f = open('myfile.txt')
s = f.readline()
i = int(s.strip())
except IOError as e:
print "I/O error({0}): {1}".format(e.errno, e.strerror)
WITH UsersRez AS
(
SELECT "user".role_id as role_id, "user".id as user_id, ROW_NUMBER()
OVER (ORDER BY timestamp DESC) AS RowNumber
FROM "user" where role_id={0}
)
SELECT RowNumber,user_id
FROM UsersRez
WHERE user_id = {1}
.format(current_user.role.id, current_user.id)class RegistrationForm(Form):
email = StringField(u'Электронная почта',
validators=[Required(REQ_TEXT),
Length(1, 64),
Email(REQ_TEXT)])
password = PasswordField(u'Пароль', validators=[
Required(REQ_TEXT)])
submit = SubmitField(u'Зарегистрироваться')
def validate_email(self, field):
if User.query.filter_by(email=field.data).first():
raise ValidationError(u'Почта уже занята')
REQ_TEXT = u'Заполните это поле'
class RegistrationForm(Form):
Nickname = TextField('Nickname', validators = [Required(REQ_TEXT)])
Password = TextField('Password', validators = [Required(u'Укажите пароль')])
email = StringField(u'Электронная почта',
validators=[Required(REQ_TEXT),
Length(1, 64),
Email(REQ_TEXT)])
def validate_email(self, field):
if User.query.filter_by(email=field.data).first():
raise ValidationError(u'Почта уже занята')
return redirect(url_for('.register_step2',
first_name=form.first_name.data,
age= form.gender.data,
gender=form.gender.data,
search_gender=form.search_gender.data
))
@mod.route('/welcome/1', methods=['GET', 'POST'])
def register_step1():
form = RegisterForm1()
if form.validate_on_submit():
'''
Что-то делаем
'''
return redirect(url_for('.register_step2', values=values))
'''
else:
return "No validate: {0}".format(dict(request.form))
Эта часть не нужна так-как form-errors на строне шаблонов можно отрабатывать
'''
return render_template('register1.html', form=form)
<form method="POST" action="{{url_for('mod.register_step1')}}" enctype="multipart/form-data">
moment().format("DD/MM/YYYY")
import datetime
class Log(db.Model):
...
date = db.Column(db.DateTime, default=datetime.datetime.now)
...
import datetime
@blueprint.route('/add', methods=["POST", "GET"])
def route():
...
form.date.data = datetime.datetime.now()
if form.validate_on_submit():
#обрабытваем форму
@app.route('/comment/<int:id>/like', methods=["POST"])
@login_required
def comment_like(id):
comment = Comment.query.get_or_404(id)
comment.like += 1
db.session.add(comment)
db.session.commit()
return jsonify({'likes': comment.like})
<a data-id="{{comment.id}}" class="like-button">Like</a>
$('.like-button').onclick(
...
//Post запрос по url, из data-id
$.ajax({
type: 'POST',
url: "/comment/"+data-id+"/like",
data: data
});
// если удался меняем innerhtml