本文整理汇总了Python中newsmeme.helpers.render_template函数的典型用法代码示例。如果您正苦于以下问题:Python render_template函数的具体用法?Python render_template怎么用?Python render_template使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render_template函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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)
示例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)
示例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)
示例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'))
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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())
示例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)