• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python helpers.render_template函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中newsmeme.helpers.render_template函数的典型用法代码示例。如果您正苦于以下问题:Python render_template函数的具体用法?Python render_template怎么用?Python render_template使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了render_template函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: edit

def edit(post_id):

    post = Post.query.get_or_404(post_id)
    post.permissions.edit.test(403)

    form = PostForm(obj=post)
    if form.validate_on_submit():

        form.populate_obj(post)
        db.session.commit()

        if g.user.id != post.author_id:
            body = render_template("emails/post_edited.html",
                                   post=post)

            message = Message(subject="Your post has been edited",
                              body=body,
                              recipients=[post.author.email])

            mail.send(message)

            flash(_("The post has been updated"), "success")

        else:
            flash(_("Your post has been updated"), "success")
        return redirect(url_for("post.view", post_id=post_id))

    return render_template("post/edit_post.html",
                           post=post,
                           form=form)
开发者ID:isleei,项目名称:newsmeme,代码行数:30,代码来源:post.py


示例2: forgot_password

def forgot_password():

    form = RecoverPasswordForm()

    if form.validate_on_submit():

        user = User.query.filter_by(email=form.email.data).first()

        if user:
            flash(_("Please see your email for instructions on "
                    "how to access your account"), "success")

            user.activation_key = str(uuid.uuid4())
            db.session.commit()

            body = render_template("emails/recover_password.html",
                                   user=user)

            message = Message(subject=_("Recover your password"),
                              body=body,
                              sender=current_app.config.get(
                                  'DEFAULT_MAIL_SENDER'),
                              recipients=[user.email])

            mail.send(message)

            return redirect(url_for("frontend.index"))

        else:

            flash(_("Sorry, no user found for that email address"), "error")

    return render_template("recover_password.html", form=form)
开发者ID:coolcoding,项目名称:newsmeme,代码行数:33,代码来源:views.py


示例3: send_message

def send_message(user_id):

    user = User.query.get_or_404(user_id)
    user.permissions.send_message.test(403)

    form = MessageForm()

    if form.validate_on_submit():

        body = render_template("emails/send_message.html",
                               user=user,
                               subject=form.subject.data,
                               message=form.message.data)

        subject = _("You have received a message from %(name)s", 
                    name=g.user.username)

        message = Message(subject=subject,
                          body=body,
                          recipients=[user.email])

        mail.send(message)

        flash(_("Your message has been sent to %(name)s", 
               name=user.username), "success")

        return redirect(url_for("user.posts", username=user.username))

    return render_template("user/send_message.html", user=user, form=form)
开发者ID:acheson77,项目名称:newsmeme,代码行数:29,代码来源:user.py


示例4: report_abuse

def report_abuse(comment_id):

    comment = Comment.query.get_or_404(comment_id)
    form = CommentAbuseForm()
    if form.validate_on_submit():

        admins = current_app.config['ADMINS']

        if admins:

            body = render_template("emails/report_abuse.html",
                               comment=comment,
                               complaint=form.complaint.data)

            message = Message(subject="Report Abuse",
                              body=body,
                              sender=g.user.email,
                              recipients=admins)

            mail.send(message)

        flash(_("Your report has been sent to the admins"), "success")

        return redirect(comment.url)

    return render_template("comment/report_abuse.html",
                           comment=comment,
                           form=form)
开发者ID:isleei,项目名称:newsmeme,代码行数:28,代码来源:comment.py


示例5: add_comment

def add_comment(post_id, parent_id=None):
    post = Post.query.get_or_404(post_id)
    post.permissions.view.test(403)

    parent = Comment.query.get_or_404(parent_id) if parent_id else None

    form = CommentForm()

    if form.validate_on_submit():
        comment = Comment(post=post,
                          parent=parent,
                          author=g.user)

        form.populate_obj(comment)

        db.session.add(comment)
        db.session.commit()

        signals.comment_added.send(post)

        flash(_("Thanks for your comment"), "success")

        author = parent.author if parent else post.author

        if author.email_alerts and author.id != g.user.id:

            subject = _("Somebody replied to your comment") if parent else \
                _("Somebody commented on your post")

            template = "emails/comment_replied.html" if parent else \
                       "emails/post_commented.html"

            body = render_template(template,
                                   author=author,
                                   post=post,
                                   parent=parent,
                                   comment=comment)

            mail.send_message(subject=subject,
                              body=body,
                              sender=current_app.config.get(
                                  'DEFAULT_MAIL_SENDER'),
                              recipients=[post.author.email])

        return redirect(comment.url)

    return render_template("add_comment.html",
                           parent=parent,
                           post=post,
                           form=form)
开发者ID:coolcoding,项目名称:newsmeme,代码行数:50,代码来源:views.py


示例6: delete

def delete(post_id):

    post = Post.query.get_or_404(post_id)
    post.permissions.delete.test(403)

    Comment.query.filter_by(post=post).delete()

    db.session.delete(post)
    db.session.commit()

    if g.user.id != post.author_id:
        body = render_template("emails/post_deleted.html",
                               post=post)

        message = Message(subject="Your post has been deleted",
                          body=body,
                          recipients=[post.author.email])

        mail.send(message)

        flash(_("The post has been deleted"), "success")

    else:
        flash(_("Your post has been deleted"), "success")

    return jsonify(success=True,
                   redirect_url=url_for('frontend.index'))
开发者ID:isleei,项目名称:newsmeme,代码行数:27,代码来源:post.py


示例7: signup

def signup():

    form = SignupForm(next=request.args.get("next"))

    if form.validate_on_submit():

        user = User()
        form.populate_obj(user)

        db.session.add(user)
        db.session.commit()

        identity_changed.send(current_app._get_current_object(),
                              identity=Identity(user.id))

        flash(_("Welcome, %(name)s", name=user.username), "success")

        next_url = form.next.data

        if not next_url or next_url == request.path:
            next_url = url_for('user.posts', username=user.username)

        return redirect(next_url)

    return render_template("signup.html", form=form)
开发者ID:coolcoding,项目名称:newsmeme,代码行数:25,代码来源:views.py


示例8: change_password

def change_password():

    user = None

    if g.user:
        user = g.user

    elif "activation_key" in request.values:
        user = User.query.filter_by(activation_key=request.values["activation_key"]).first()

    if user is None:
        abort(403)

    form = ChangePasswordForm(activation_key=user.activation_key)

    if form.validate_on_submit():

        user.password = form.password.data
        user.activation_key = None

        db.session.commit()

        flash(_("Your password has been changed, " "please log in again"), "success")

        return redirect(url_for("account.login"))

    return render_template("account/change_password.html", form=form)
开发者ID:wq1308786830,项目名称:danjac-newsmeme,代码行数:27,代码来源:account.py


示例9: change_password

def change_password():

    user = None

    if g.user:
        user = g.user

    elif 'activation_key' in request.values:
        user = User.query.filter_by(
            activation_key=request.values['activation_key']).first()

    if user is None:
        abort(403)

    form = ChangePasswordForm(activation_key=user.activation_key)

    if form.validate_on_submit():

        user.password = form.password.data
        user.activation_key = None

        db.session.commit()

        flash(_("Your password has been changed, "
                "please log in again"), "success")
        # 修改成功后,强制用户退出
        identity_changed.send(current_app._get_current_object(),
                              identity=AnonymousIdentity())

        return redirect(url_for("account.login"))

    return render_template("change_password.html", form=form)
开发者ID:coolcoding,项目名称:newsmeme,代码行数:32,代码来源:views.py


示例10: contact

def contact():

    if g.user:
        form = ContactForm(name=g.user.username,
                           email=g.user.email)

    else:
        form = ContactForm()

    if form.validate_on_submit():

        admins = current_app.config.get('ADMINS', [])

        from_address = "%s <%s>" % (form.name.data, 
                                    form.email.data)

        if admins:
            message = Message(subject=form.subject.data,
                              body=form.message.data,
                              recipients=admins,
                              sender=from_address)

            mail.send(message)
        
        flash(_("Thanks, your message has been sent to us"), "success")

        return redirect(url_for('frontend.index'))

    return render_template("contact.html", form=form)
开发者ID:ericx10ng,项目名称:newsmeme,代码行数:29,代码来源:frontend.py


示例11: deadpool

def deadpool(page=1):

    page_obj = Post.query.deadpooled().restricted(g.user).as_list().\
                          paginate(page, per_page=Post.PER_PAGE)

    page_url = lambda page: url_for("frontend.deadpool", page=page)

    return render_template("deadpool.html", 
                           page_obj=page_obj, 
                           page_url=page_url)
开发者ID:ericx10ng,项目名称:newsmeme,代码行数:10,代码来源:frontend.py


示例12: latest

def latest(page=1):
    
    page_obj = Post.query.popular().restricted(g.user).as_list().\
                          paginate(page, per_page=Post.PER_PAGE)

    page_url = lambda page: url_for("frontend.latest", page=page)

    return render_template("latest.html", 
                           page_obj=page_obj, 
                           page_url=page_url)
开发者ID:ericx10ng,项目名称:newsmeme,代码行数:10,代码来源:frontend.py


示例13: follow

def follow(user_id):

    user = User.query.get_or_404(user_id)
    g.user.follow(user)
    db.session.commit()

    body = render_template("emails/followed.html", user=user)

    mail.send_message(subject=_("%s is now following you" % g.user.username), body=body, recipients=[user.email])

    return jsonify(success=True, reload=True)
开发者ID:wq1308786830,项目名称:danjac-newsmeme,代码行数:11,代码来源:account.py


示例14: login

def login():

    form = OpenIdLoginForm(next=request.args.get("next"))

    if form.validate_on_submit():
        session['next'] = form.next.data

        return oid.try_login(form.openid.data,
                             ask_for=('email', 'fullname', 'nickname'))

    return render_template("openid_login.html",
                           form=form,
                           error=oid.fetch_error())
开发者ID:coolcoding,项目名称:newsmeme,代码行数:13,代码来源:views.py


示例15: edit

def edit():

    form = EditAccountForm(g.user)

    if form.validate_on_submit():

        form.populate_obj(g.user)
        db.session.commit()

        flash(_("Your account has been updated"), "success")

        return redirect(url_for("frontend.index"))

    return render_template("edit_account.html", form=form)
开发者ID:coolcoding,项目名称:newsmeme,代码行数:14,代码来源:views.py


示例16: tag

def tag(slug, page=1):
    tag = Tag.query.filter_by(slug=slug).first_or_404()

    page_obj = tag.posts.restricted(g.user).as_list().\
                    paginate(page, per_page=Post.PER_PAGE)

    page_url = lambda page: url_for('frontend.tag',
                                    slug=slug,
                                    page=page)

    return render_template("tag.html", 
                           tag=tag,
                           page_url=page_url,
                           page_obj=page_obj)
开发者ID:ericx10ng,项目名称:newsmeme,代码行数:14,代码来源:frontend.py


示例17: following

def following(username, page=1):

    user = User.query.filter_by(username=username).first_or_404()

    num_posts = Post.query.filter_by(author_id=user.id).\
        restricted(g.user).count()

    num_comments = Comment.query.filter_by(author_id=user.id).\
        restricted(g.user).count()
   
    following = user.get_following().order_by(User.username.asc())

    return render_template("user/following.html",
                           user=user,
                           num_posts=num_posts,
                           num_comments=num_comments,
                           following=following)
开发者ID:acheson77,项目名称:newsmeme,代码行数:17,代码来源:user.py


示例18: submit

def submit():

    form = PostForm()
    
    if form.validate_on_submit():

        post = Post(author=g.user)
        form.populate_obj(post)

        db.session.add(post)
        db.session.commit()

        flash(_("Thank you for posting"), "success")

        return redirect(url_for("frontend.latest"))

    return render_template("submit.html", form=form)
开发者ID:ericx10ng,项目名称:newsmeme,代码行数:17,代码来源:frontend.py


示例19: view

def view(post_id, slug=None):
    post = Post.query.get_or_404(post_id)
    if not post.permissions.view:
        if not g.user:
            flash(_("You must be logged in to see this post"), "error")
            return redirect(url_for("account.login", next=request.path))
        else:
            flash(_("You must be a friend to see this post"), "error")
            abort(403)

    def edit_comment_form(comment):
        return CommentForm(obj=comment)

    return render_template("post/post.html",
                           comment_form=CommentForm(),
                           edit_comment_form=edit_comment_form,
                           post=post)
开发者ID:isleei,项目名称:newsmeme,代码行数:17,代码来源:post.py


示例20: delete

def delete():

    # confirm password & recaptcha
    form = DeleteAccountForm()

    if form.validate_on_submit():

        db.session.delete(g.user)
        db.session.commit()

        identity_changed.send(current_app._get_current_object(), identity=AnonymousIdentity())

        flash(_("Your account has been deleted"), "success")

        return redirect(url_for("frontend.index"))

    return render_template("account/delete_account.html", form=form)
开发者ID:wq1308786830,项目名称:danjac-newsmeme,代码行数:17,代码来源:account.py



注:本文中的newsmeme.helpers.render_template函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python newspaper.build函数代码示例发布时间:2022-05-27
下一篇:
Python logger.error函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap