Ejemplo n.º 1
0
def post(id):
    BlogCount.add_blogview(db)
    form = CommentForm(request.form)
    post = Post.query.get_or_404(id)
    if form.validate_on_submit():
        comment = Comment(body=form.body.data,
                          post=post,
                          author=current_user._get_current_object())

        db.session.add(comment)
        db.session.commit()
        flash('Your comment has been published.')
        return redirect(url_for('main.post', id=post.id, page=-1))
    page = request.args.get('page', 1, type=int)
    if page == -1:
        page = (post.comments.count() -
                1) // current_app.config['FLASKY_COMMENTS_PER_PAGE'] + 1
    pagination = post.comments.order_by(Comment.timestamp.desc()).paginate(
        page,
        per_page=current_app.config['FLASKY_COMMENTS_PER_PAGE'],
        error_out=False)
    comments = pagination.items
    post.add_view(post, db)
    # return render_template('post.html', post=post, User=User,form=form, comments=comments, pagination=pagination, page=page)
    return render_template('post.html',
                           post=post,
                           Users=Users,
                           comments=comments,
                           pagination=pagination,
                           page=page,
                           form=form,
                           endpoint='.post',
                           id=post.id)
Ejemplo n.º 2
0
def login():
    BlogCount.add_blogview(db)
    form = LoginForm()
    # 判断是否是验证提交
    if form.validate_on_submit():
        user = Users.query.filter_by(email=form.email.data).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user, form.remember_me.data)
            flash('Login Success')
            return redirect(request.args.get('next') or url_for('auth.index'))
        flash('Invalid username or password!')
    return render_template('auth/login.html', form=form)
Ejemplo n.º 3
0
def menu(id):
    BlogCount.add_blogview(db)
    page = request.args.get('page', 1, type=int)
    pagination = Menu.query.get_or_404(id).posts.order_by(
        Post.update_time.desc()).paginate(
            page,
            per_page=current_app.config['FLASKY_POSTS_INFO_PAGE'],
            error_out=False)
    posts = pagination.items
    return render_template('index.html',
                           posts=posts,
                           pagination=pagination,
                           endpoint='.menu',
                           id=id)
Ejemplo n.º 4
0
def zc154165483():
    BlogCount.add_blogview(db)
    form = RegistrationForm()
    if form.validate_on_submit():
        user = Users(
            email=form.email.data,
            username=form.username.data,
            password=form.password.data,
        )
        db.session.add(user)
        db.session.commit()  # 写入数据库
        token = user.generate_confirmation_token()  # 获取用户的token令牌
        # 发送确认邮件
        send_email(user.email,
                   'Confirm Your Account',
                   'auth/email/confirm',
                   user=user,
                   token=token)
        flash('A confirmation email has been sent to you by email.')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)
Ejemplo n.º 5
0
def about():
    BlogCount.add_blogview(db)
    return render_template('about.html')