本文整理汇总了Python中pypress.helpers.render_template函数的典型用法代码示例。如果您正苦于以下问题:Python render_template函数的具体用法?Python render_template怎么用?Python render_template使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render_template函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: people
def people(username,page=1):
people = User.query.get_by_username(username)
form = TwitterForm()
if form.validate_on_submit():
api = people.twitter_api
if api is None:
return redirect(url_for('account.twitter'))
content = form.content.data.encode("utf-8")
status = people.post_twitter(content)
if status:
flash(_("Twitter posting is success"),"success")
return redirect(url_for('frontend.people',
username=username,
page=page))
else:
flash(_("Twitter posting is failed"),"error")
page_obj = Post.query.filter(Post.author_id==people.id).as_list()\
.paginate(page,per_page=Post.PER_PAGE)
page_url = lanbda page: url_for("post.people",
username=username,
page=page)
return render_template("blog/people.html",
form=form,
page_obj=page_obj,
page_url=page_url,
people=people)
示例2: login
def login():
form = LoginForm(login=request.args.get('login',None),
next=request.args.get('next',None))
if form.validate_on_submit():
user, authenticated = User.query.authenticate(form.login.data,
form.password.data)
if user and authenticated:
session.permanent = form.remember.data
identity_changed.send(current_app._get_current_object(),
identity=Identity(user.id))
flash(_("Welcome back, %(name)s", name=user.username), "success")
next_url = form.next.data
if not next_url or next_url == request.path:
next_url = url_for('frontend.blog', username=user.username)
return redirect(next_url)
else:
flash(_("Sorry, invalid login"), "error")
return render_template("account/login.html", form=form)
示例3: add_comment
def add_comment(post_id, parent_id=None):
post = Post.query.get_or_404(post_id)
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,
ip=ip2long(request.environ['REMOTE_ADDR']))
form.populate_obj(comment)
if g.user:
comment.author = g.user
db.session.add(comment)
db.session.commit()
signals.comment_added.send(post)
flash(_("Thanks for your comment"), "success")
return redirect(comment.url)
return render_template("blog/add_comment.html",
parent=parent,
post=post,
form=form)
示例4: signup
def signup():
form = SignupForm(next=request.args.get('next',None))
if form.validate_on_submit():
code = UserCode.query.filter_by(code=form.code.data).first()
if code:
user = User(role=code.role)
form.populate_obj(user)
db.session.add(user)
db.session.delete(code)
db.session.commit()
identity_changed.send(current_app._get_current_object(),
identity=Identity(user.id))
flash(_("Welcome, %(name)s", name=user.nickname), "success")
next_url = form.next.data
if not next_url or next_url == request.path:
next_url = url_for('frontend.blog', username=user.username)
return redirect(next_url)
else:
form.code.errors.append(_("Code is not allowed"))
return render_template("account/signup.html", form=form)
示例5: template_edit
def template_edit(path):
path = os.path.join(current_app.root_path, 'templates', "%s.html" % path)
html = ""
try:
f = open(path)
html = f.read()
f.close()
except:
flash(_("Template file does not exists"), "error")
form = TemplateForm(html=html.decode('utf8'))
if form.validate_on_submit():
f = open(path, 'w')
f.write(form.html.data.encode('utf8'))
f.close()
flash(_("Saving success"), "success")
return redirect(url_for("frontend.index"))
return render_template("blog/template_edit.html",
form=form,
path=path)
示例6: index
def index(page=1):
if page < 1:
page = 1
ups = Upload.query
page_obj = ups.paginate(page=page, per_page=Upload.PER_PAGE)
page_url = lambda page: url_for("uploads.index", page=page)
return render_template("blog/uploads.html", page_obj=page_obj, page_url=page_url)
示例7: index
def index(year=None,month=None,day=None,page=1):
if page<1:page=1
page_obj = Post.query.archive(year,month,day).as_list()\
.paginate(page,per_page=Post.PER_PAGE)
page_url = lambda page:url_for("post.index",
year=year,
month=month,
day=day,
page=page)
return render_template("blog/list.html",
page_obj=page_obj,
page_url=page_url)
示例8: tag
def tag(slug, page=1):
tag = Tag.query.filter_by(slug=slug).first_or_404()
page_obj = tag.posts.as_list() \
.paginate(page, per_page=Post.PER_PAGE)
page_url = lambda page: url_for("post.tag",
slug=slug,
page=page)
return render_template("blog/list.html",
page_obj=page_obj,
page_url=page_url)
示例9: index
def index(page=1):
links = Link.query
if g.user is None:
links = links.filter(Link.passed==True)
page_obj = links.paginate(page=page, per_page=Link.PER_PAGE)
page_url = lambda page: url_for("link.index",page=page)
return render_template("blog/links.html",
page_obj=page_obj,
page_url=page_url)
示例10: add
def add():
form = UploadForm()
if "file" in request.files:
filename = uploader.save(request.files["file"])
upload = Upload(file=filename)
db.session.add(upload)
db.session.commit()
flash(_("Upload successful"), "success")
return redirect(url_for("uploads.index"))
return render_template("blog/add_upload.html", form=form)
示例11: search
def search(page=1):
keywords = request.args.get('q','').strip()
if not keywords:
return redirect(url_for("frontend.index"))
page_obj = Post.query.search(keywords).as_list()\
.paginate(page,per_page=Post.PER_PAGE)
if page_obj.total == 1:
post = page_obj.items[0]
return redirect(post.url)
page_url = lambda page:url_for('frontend.search',
page=page,
keywords=keywords)
return render_template("blog/search_result.html",
page_obj=page_obj,
page_url=page_url,
keywords=keywords)
示例12: 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(_("Posting success"), "success")
return redirect(post.url)
return render_template("blog/submit.html", form=form)
示例13: edit
def edit(post_id):
post = Post.query.get_or_404(post_id)
form = PostForm(title=post.title, slug=post.slug, content=post.content, tags=post.tags, obj=post)
if form.validate_on_submit():
form.populate_obj(post)
db.session.commit()
flash(_("Post has been changed"), "success")
return redirect(post.url)
return render_template("admin/submit.html", form=form)
示例14: add
def add():
form = LinkForm()
if form.validate_on_submit():
link = Link()
form.populate_obj(link)
if g.user and g.user.is_moderator:
link.passed = True
db.session.add(link)
db.session.commit()
flash(_("Adding success"), "success")
return redirect(url_for('link.index'))
return render_template("blog/add_link.html", form=form)
示例15: post
def post(uear,month,day,slug):
post = Post.query.get_by_slug(slug)
date = (post.created_date.year,
post.created_date.month,
post.created_date.day)
if date != (year, month, day):
return redirect(post.url)
prev_post = Post.query.filter(Post.created_date<post.created_date) \
.first()
next_post = Post.query.filter(Post.created_date>post.created_date) \
.order_by('created_date asc').first()
return render_template("blog/view.html",
post=post,
prev_post=prev_post,
next_post=next_post,
comment_form=CommentForm())