当前位置: 首页>>代码示例>>Python>>正文


Python helpers.render_template函数代码示例

本文整理汇总了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)
开发者ID:zhangst23,项目名称:tutorial,代码行数:27,代码来源:frontend.py

示例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)
开发者ID:kipanshi,项目名称:pypress,代码行数:30,代码来源:account.py

示例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)
开发者ID:silverymoon,项目名称:pypress,代码行数:30,代码来源:post.py

示例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)
开发者ID:kipanshi,项目名称:pypress,代码行数:31,代码来源:account.py

示例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)
开发者ID:lomatus,项目名称:pypress,代码行数:27,代码来源:frontend.py

示例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)
开发者ID:silverymoon,项目名称:pypress,代码行数:10,代码来源:uploads.py

示例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)
开发者ID:zhangst23,项目名称:tutorial,代码行数:12,代码来源:frontend.py

示例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)
开发者ID:lomatus,项目名称:pypress,代码行数:14,代码来源:frontend.py

示例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)
开发者ID:nasawz,项目名称:pypress,代码行数:14,代码来源:link.py

示例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)
开发者ID:silverymoon,项目名称:pypress,代码行数:16,代码来源:uploads.py

示例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)
开发者ID:zhangst23,项目名称:tutorial,代码行数:17,代码来源:frontend.py

示例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)
开发者ID:silverymoon,项目名称:pypress,代码行数:17,代码来源:post.py

示例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)
开发者ID:ajaxj,项目名称:fkmv,代码行数:17,代码来源:post.py

示例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)
开发者ID:nasawz,项目名称:pypress,代码行数:20,代码来源:link.py

示例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())
开发者ID:zhangst23,项目名称:tutorial,代码行数:20,代码来源:frontend.py


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