Python bottle 模块,post() 实例源码

我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用bottle.post()

项目:Mmrz-Sync    作者:zhanglintc    | 项目源码 | 文件源码
def set_last_import_time_int(self):
        self.load_pkl()
        self.pkl["last_import_time_int"] = int(time.time())
        self.dump_pkl()

# pkl data format:
# pkl = {   
#     book_name: str,
#     total_lines: int,
#     last_import_time: str,
#     last_import_time_int: int,
# }

# Refer to: http://stackoverflow.com/questions/16865997/python-bottle-module-causes-error-413-request-entity-too-large
# There was a bug:
# If a client post something with a very large parameter, it will be encountered a "broken pipe" problem.
# The line below can change the Bottle's acceptable max-size of request.
# So this bug is no longer exist.
项目:M101P-mongodb-course-2016    作者:mahasagar    | 项目源码 | 文件源码
def show_post(permalink="notfound"):

    cookie = bottle.request.get_cookie("session")

    username = sessions.get_username(cookie)
    permalink = cgi.escape(permalink)

    print "about to query on permalink = ", permalink
    post = posts.get_post_by_permalink(permalink)

    if post is None:
        bottle.redirect("/post_not_found")

    # init comment form fields for additional comment
    comment = {'name': "", 'body': "", 'email': ""}

    return bottle.template("entry_template", dict(post=post, username=username, errors="", comment=comment))


# used to process a comment on a blog post
项目:M101P-mongodb-course-2016    作者:mahasagar    | 项目源码 | 文件源码
def post_comment_like():
    permalink = bottle.request.forms.get("permalink")
    permalink = cgi.escape(permalink)

    comment_ordinal_str = bottle.request.forms.get("comment_ordinal")

    comment_ordinal = int(comment_ordinal_str)

    post = posts.get_post_by_permalink(permalink)
    if post is None:
        bottle.redirect("/post_not_found")
        return

    # it all looks good. increment the ordinal
    posts.increment_likes(permalink, comment_ordinal)

    bottle.redirect("/post/" + permalink)
项目:experiment-manager    作者:softfire-eu    | 项目源码 | 文件源码
def register():
    """Send out registration email"""
    logger.debug(("got body: %s" % request.body.read().decode("utf-8")))
    if check_if_authorized(post_get('username')):
        aaa.create_user(post_get('username'), 'user', post_get('password'))
    else:
        return dict(
            ok=False,
            msg="username not pre authorized"
        )
    return 'User created'


# @bottle.post('/reset_password')
# def send_password_reset_email():
#     """Send out password reset email"""
#     aaa.send_password_reset_email(
#         username=post_get('username'),
#         email_addr=post_get('email_address')
#     )
#     return 'Please check your mailbox.'


# @bottle.post('/change_password')
# def change_password():
#     """Change password"""
#     aaa.reset_password(post_get('reset_code'), post_get('password'))
#     return 'Thanks. <a href="/login">Go to login</a>'
项目:python-exercise    作者:geniustesda    | 项目源码 | 文件源码
def upload_view():
    return """
        <form action="/upload" method="post" enctype="multipart/form-data">
          <input type="text" name="name" />
          <input type="file" name="data" />
          <input type="submit" name="submit" value="upload now" />
        </form>
        """
项目:python-exercise    作者:geniustesda    | 项目源码 | 文件源码
def login():
    return '''
        <form action="/login" method="post">
            Username: <input name="username" type="text" />
            Password: <input name="password" type="password" />
            <input value="Login" type="submit" />
        </form>
    '''
项目:nlp100    作者:r9y9    | 项目源码 | 文件源码
def index():
    return """
    <form action="/" method="post">
    Name: <input name="name" type="text" />
    Alias name: <input name="alias_name" type="text" />
    Tag: <input name="tag" type="text" />
    <input value="Search" type="submit" />
    </form>
    """
项目:Pardus-Bulut    作者:ferhatacikalin    | 项目源码 | 文件源码
def test_get(self):
        """ WSGI: GET routes"""
        @bottle.route('/')
        def test(): return 'test'
        self.assertStatus(404, '/not/found')
        self.assertStatus(405, '/', post="var=value")
        self.assertBody('test', '/')
项目:Pardus-Bulut    作者:ferhatacikalin    | 项目源码 | 文件源码
def test_post(self):
        """ WSGI: POST routes"""
        @bottle.route('/', method='POST')
        def test(): return 'test'
        self.assertStatus(404, '/not/found')
        self.assertStatus(405, '/')
        self.assertBody('test', '/', post="var=value")
项目:Pardus-Bulut    作者:ferhatacikalin    | 项目源码 | 文件源码
def test_decorators(self):
        def foo(): return bottle.request.method
        bottle.get('/')(foo)
        bottle.post('/')(foo)
        bottle.put('/')(foo)
        bottle.delete('/')(foo)
        for verb in 'GET POST PUT DELETE'.split():
            self.assertBody(verb, '/', method=verb)
项目:Pardus-Bulut    作者:ferhatacikalin    | 项目源码 | 文件源码
def test_method_list(self):
        @bottle.route(method=['GET','post'])
        def test(): return 'ok'
        self.assertBody('ok', '/test', method='GET')
        self.assertBody('ok', '/test', method='POST')
        self.assertStatus(405, '/test', method='PUT')
项目:Pardus-Bulut    作者:ferhatacikalin    | 项目源码 | 文件源码
def test_module_shortcuts(self):
        for name in '''route get post put delete error mount
                       hook install uninstall'''.split():
            short = getattr(bottle, name)
            original = getattr(bottle.app(), name)
            self.assertWraps(short, original)
项目:antitools    作者:bufubaoni    | 项目源码 | 文件源码
def upload():
    if request.method.lower() == "post":
        file = request.files.get("file")
        file.save("img/" + file.filename)
        return file.filename
    else:
        return ("<form method='post' action='/upload' enctype='multipart/form-data'>"
                "<input type='file' name='file'/>"
                "</br>"
                "<input type='submit'/>"
                "</form> ")
项目:ssland    作者:laobubu    | 项目源码 | 文件源码
def admin_api(uri):
    def admin_api_out(func):
        @wraps(func)
        @post(uri)
        @require_login
        @json_api
        def func_wrapper(*args, **kwargs):
            if not is_admin: return {"error": "not_admin"}
            return func(*args, **kwargs)
    return admin_api_out

# get salted password from request.forms
项目:M101P-mongodb-course-2016    作者:mahasagar    | 项目源码 | 文件源码
def post_new_comment():
    name = bottle.request.forms.get("commentName")
    email = bottle.request.forms.get("commentEmail")
    body = bottle.request.forms.get("commentBody")
    permalink = bottle.request.forms.get("permalink")

    post = posts.get_post_by_permalink(permalink)
    cookie = bottle.request.get_cookie("session")

    username = sessions.get_username(cookie)

    # if post not found, redirect to post not found error
    if post is None:
        bottle.redirect("/post_not_found")
        return

    # if values not good, redirect to view with errors

    if name == "" or body == "":
        # user did not fill in enough information

        # init comment for web form
        comment = {'name': name, 'email': email, 'body': body}

        errors = "Post must contain your name and an actual comment."
        return bottle.template("entry_template", dict(post=post, username=username, errors=errors, comment=comment))

    else:

        # it all looks good, insert the comment into the blog post and redirect back to the post viewer
        posts.add_comment(permalink, name, email, body)
        bottle.redirect("/post/" + permalink)
项目:M101P-mongodb-course-2016    作者:mahasagar    | 项目源码 | 文件源码
def post_not_found():
    return "Sorry, post not found"


# Displays the form allowing a user to add a new post. Only works for logged in users
项目:M101P-mongodb-course-2016    作者:mahasagar    | 项目源码 | 文件源码
def get_newpost():

    cookie = bottle.request.get_cookie("session")
    username = sessions.get_username(cookie)  # see if user is logged in
    if username is None:
        bottle.redirect("/login")

    return bottle.template("newpost_template", dict(subject="", body = "", errors="", tags="", username=username))

#
# Post handler for setting up a new post.
# Only works for logged in user.
项目:M101P-mongodb-course-2016    作者:mahasagar    | 项目源码 | 文件源码
def post_newpost():
    title = bottle.request.forms.get("subject")
    post = bottle.request.forms.get("body")
    tags = bottle.request.forms.get("tags")

    cookie = bottle.request.get_cookie("session")
    username = sessions.get_username(cookie)  # see if user is logged in
    if username is None:
        bottle.redirect("/login")

    if title == "" or post == "":
        errors = "Post must contain a title and blog entry"
        return bottle.template("newpost_template", dict(subject=cgi.escape(title, quote=True), username=username,
                                                        body=cgi.escape(post, quote=True), tags=tags, errors=errors))

    # extract tags
    tags = cgi.escape(tags)
    tags_array = extract_tags(tags)

    # looks like a good entry, insert it escaped
    escaped_post = cgi.escape(post, quote=True)

    # substitute some <p> for the paragraph breaks
    newline = re.compile('\r?\n')
    formatted_post = newline.sub("<p>", escaped_post)

    permalink = posts.insert_entry(title, formatted_post, tags_array, username)
    print "here"
    # now bottle.redirect to the blog permalink
    bottle.redirect("/post/" + permalink)


# displays the initial blog signup form
项目:M101P-mongodb-course-2016    作者:mahasagar    | 项目源码 | 文件源码
def post_new_comment():
    name = bottle.request.forms.get("commentName")
    email = bottle.request.forms.get("commentEmail")
    body = bottle.request.forms.get("commentBody")
    permalink = bottle.request.forms.get("permalink")

    post = posts.get_post_by_permalink(permalink)
    cookie = bottle.request.get_cookie("session")

    username = sessions.get_username(cookie)

    # if post not found, redirect to post not found error
    if post is None:
        bottle.redirect("/post_not_found")
        return

    # if values not good, redirect to view with errors

    if name == "" or body == "":
        # user did not fill in enough information

        # init comment for web form
        comment = {'name': name, 'email': email, 'body': body}

        errors = "Post must contain your name and an actual comment."
        return bottle.template("entry_template",
                               {"post": post, "username": username,
                                "errors": errors, "comment": comment})

    else:

        # it all looks good, insert the comment into the blog post and redirect
        # back to the post viewer
        posts.add_comment(permalink, name, email, body)

        bottle.redirect("/post/" + permalink)


# used to process a like on a blog post
项目:M101P-mongodb-course-2016    作者:mahasagar    | 项目源码 | 文件源码
def post_not_found():
    return "Sorry, post not found"


# Displays the form allowing a user to add a new post. Only works for
# logged-in users
项目:M101P-mongodb-course-2016    作者:mahasagar    | 项目源码 | 文件源码
def get_newpost():

    cookie = bottle.request.get_cookie("session")
    username = sessions.get_username(cookie)  # see if user is logged in
    if username is None:
        bottle.redirect("/login")

    return bottle.template("newpost_template",
                           {"subject": "", "body": "", "errors": "",
                            "tags": "", "username": username})


# Post handler for setting up a new post.
# Only works for logged in user.
项目:M101P-mongodb-course-2016    作者:mahasagar    | 项目源码 | 文件源码
def post_newpost():
    title = bottle.request.forms.get("subject")
    post = bottle.request.forms.get("body")
    tags = bottle.request.forms.get("tags")

    cookie = bottle.request.get_cookie("session")
    username = sessions.get_username(cookie)  # see if user is logged in
    if username is None:
        bottle.redirect("/login")

    if title == "" or post == "":
        errors = "Post must contain a title and blog entry"
        return bottle.template("newpost_template",
                               {"subject": cgi.escape(title, quote=True),
                                "username": username,
                                "body": cgi.escape(post, quote=True),
                                "tags": tags, "errors": errors})

    # extract tags
    tags = cgi.escape(tags)
    tags_array = extract_tags(tags)

    # looks like a good entry, insert it escaped
    escaped_post = cgi.escape(post, quote=True)

    # substitute some <p> for the paragraph breaks
    newline = re.compile('\r?\n')
    formatted_post = newline.sub("<p>", escaped_post)

    permalink = posts.insert_entry(title, formatted_post, tags_array, username)

    # now bottle.redirect to the blog permalink
    bottle.redirect("/post/" + permalink)


# displays the initial blog signup form
项目:besserberg    作者:Vnet-as    | 项目源码 | 文件源码
def postprocess_pdf(input_pdf, qr_data, qr_x=545, qr_y=20, version=None):
    """ PDF post-processor. Append QR code on each PDF page.

    :param input_pdf: PDF byte content
    :param qr_data: QR code data
    :param qr_x: X possition of QR image
    :param qr_y: Y possition of QR image
    """

    qr = pyqrcode.create(qr_data, version=version)

    eps = StringIO()
    qr.eps(eps)
    eps.seek(0)

    qr_pdf = BytesIO()

    qr_img = Image(file=BytesIO(bytes(eps.read(), 'utf-8')))
    qr_img.format = 'pdf'
    qr_img.save(qr_pdf)

    qr_page = PdfFileReader(qr_pdf).getPage(0)

    output_writer = PdfFileWriter()
    output_pdf = BytesIO()

    for page in PdfFileReader(BytesIO(input_pdf)).pages:
        page.mergeTranslatedPage(qr_page, qr_x, qr_y)
        output_writer.addPage(page)

    output_writer.write(output_pdf)
    output_pdf.seek(0)

    return output_pdf.read()
项目:bottle-py    作者:today-open    | 项目源码 | 文件源码
def index():
    return '''<form enctype="multipart/form-data" action="./upload" method="post">
                <p>File: <input type="file" name="file"></p>
                <p><input type="submit" value="Upload"></p>
            </form>'''