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


Python current_app.config方法代码示例

本文整理汇总了Python中flask.current_app.config方法的典型用法代码示例。如果您正苦于以下问题:Python current_app.config方法的具体用法?Python current_app.config怎么用?Python current_app.config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask.current_app的用法示例。


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

示例1: get_browser

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import config [as 别名]
def get_browser():
    if "browser" not in g:
        options = webdriver.ChromeOptions()
        options.add_argument("no-sandbox")
        options.add_argument("--disable-gpu")
        options.add_argument("--window-size=800,600")
        options.add_argument("--disable-dev-shm-usage")
        options.set_headless()
        host = "chrome" if current_app.config["DEBUG"] else "127.0.0.1"
        g.browser = webdriver.Remote(
            command_executor=f"http://{host}:4444/wd/hub",
            desired_capabilities=DesiredCapabilities.CHROME,
            options=options,
        )
    return g.browser 
开发者ID:materialsproject,项目名称:MPContribs,代码行数:17,代码来源:views.py

示例2: test_interest_form_post_triggers_slack_notification

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import config [as 别名]
def test_interest_form_post_triggers_slack_notification(self, testapp):
        ''' A valid interest form post triggers a Slack notification.
        '''

        # set a fake Slack webhook URL
        fake_webhook_url = 'http://webhook.example.com/'
        current_app.config['SLACK_WEBHOOK_URL'] = fake_webhook_url

        # create a mock to receive POST requests to that URL
        responses.add(responses.POST, fake_webhook_url, status=200)

        # post an interest form submission
        testapp.post("/interest/", params=dict(name="Jean Weaver", agency="Clinton Police Department", location="Clinton, OK", phone="580-970-3338", email="jean.weaver@example.com", comments="I'm interested in Comport as an open-source tool!"))

        # test the captured post payload
        post_body = json.loads(responses.calls[0].request.body)
        assert 'New Interest Form Submission!' in post_body['text']

        # delete the fake Slack webhook URL
        del(current_app.config['SLACK_WEBHOOK_URL'])
        # reset the mock
        responses.reset() 
开发者ID:codeforamerica,项目名称:comport,代码行数:24,代码来源:test_interest_form.py

示例3: __init__

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import config [as 别名]
def __init__(self, response, status=None, headers=None, **kwargs):
        """ Init a JSON response
        :param response: Response data
        :type response: *
        :param status: Status code
        :type status: int|None
        :param headers: Additional headers
        :type headers: dict|None
        """
        # Store response
        self._response_data = self.preprocess_response_data(response)

        # PrettyPrint?
        try:
            indent = 2 if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] and not request.is_xhr else None
        except RuntimeError:  # "RuntimeError: working outside of application context"
            indent = None

        # Init super
        super(JsonResponse, self).__init__(
            json.dumps(self._response_data, indent=indent),
            headers=headers, status=status, mimetype='application/json',
            direct_passthrough=True, **kwargs) 
开发者ID:kolypto,项目名称:py-flask-jsontools,代码行数:25,代码来源:response.py

示例4: get_user_posts

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import config [as 别名]
def get_user_posts(id):
    user = User.query.get_or_404(id)
    page = request.args.get('page', 1, type=int)
    pagination = user.posts.order_by(Post.timestamp.desc()).paginate(
        page, per_page=current_app.config['CIRCULATE_POSTS_PER_PAGE'],
        error_out=False)
    posts = pagination.items
    prev = None
    if pagination.has_prev:
        prev = url_for('api.get_user_posts', page=page-1, _external=True)
    next = None
    if pagination.has_next:
        next = url_for('api.get_user_posts', page=page+1, _external=True)
    return jsonify({
        'posts': [post.to_json() for post in posts],
        'prev': prev,
        'next': next,
        'count': pagination.total
    }) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:21,代码来源:users.py

示例5: get_user_followed_posts

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import config [as 别名]
def get_user_followed_posts(id):
    user = User.query.get_or_404(id)
    page = request.args.get('page', 1, type=int)
    pagination = user.followed_posts.order_by(Post.timestamp.desc()).paginate(
        page, per_page=current_app.config['CIRCULATE_POSTS_PER_PAGE'],
        error_out=False)
    posts = pagination.items
    prev = None
    if pagination.has_prev:
        prev = url_for('api.get_user_followed_posts', page=page-1,
                       _external=True)
    next = None
    if pagination.has_next:
        next = url_for('api.get_user_followed_posts', page=page+1,
                       _external=True)
    return jsonify({
        'posts': [post.to_json() for post in posts],
        'prev': prev,
        'next': next,
        'count': pagination.total
    }) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:23,代码来源:users.py

示例6: get_comments

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import config [as 别名]
def get_comments():
    page = request.args.get('page', 1, type=int)
    pagination = Comment.query.order_by(Comment.timestamp.desc()).paginate(
        page, per_page=current_app.config['CIRCULATE_COMMENTS_PER_PAGE'],
        error_out=False)
    comments = pagination.items
    prev = None
    if pagination.has_prev:
        prev = url_for('api.get_comments', page=page-1, _external=True)
    next = None
    if pagination.has_next:
        next = url_for('api.get_comments', page=page+1, _external=True)
    return jsonify({
        'comments': [comment.to_json() for comment in comments],
        'prev': prev,
        'next': next,
        'count': pagination.total
    }) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:20,代码来源:comments.py

示例7: get_post_comments

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import config [as 别名]
def get_post_comments(id):
    post = Post.query.get_or_404(id)
    page = request.args.get('page', 1, type=int)
    pagination = post.comments.order_by(Comment.timestamp.asc()).paginate(
        page, per_page=current_app.config['CIRCULATE_COMMENTS_PER_PAGE'],
        error_out=False)
    comments = pagination.items
    prev = None
    if pagination.has_prev:
        prev = url_for('api.get_post_comments', page=page-1, _external=True)
    next = None
    if pagination.has_next:
        next = url_for('api.get_post_comments', page=page+1, _external=True)
    return jsonify({
        'comments': [comment.to_json() for comment in comments],
        'prev': prev,
        'next': next,
        'count': pagination.total
    }) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:21,代码来源:comments.py

示例8: get_posts

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import config [as 别名]
def get_posts():
    page = request.args.get('page', 1, type=int)
    pagination = Post.query.paginate(
        page, per_page=current_app.config['CIRCULATE_POSTS_PER_PAGE'],
        error_out=False)
    posts = pagination.items
    prev = None
    if pagination.has_prev:
        prev = url_for('api.get_posts', page=page-1, _external=True)
    next = None
    if pagination.has_next:
        next = url_for('api.get_posts', page=page+1, _external=True)
    return jsonify({
        'posts': [post.to_json() for post in posts],
        'prev': prev,
        'next': next,
        'count': pagination.total
    }) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:20,代码来源:posts.py

示例9: delete

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import config [as 别名]
def delete(self, pk):
        '''
        删除图片
        '''
        user = request.user
        image = Image.query.filter_by(id=pk, user=user).get_or_404('图片不存在')
        serializer = ImageSerializer(image)
        img_path = os.path.join(current_app.config['UPLOAD_FOLDER_ROOT'],
                                image.url)
        # 删除原图
        if os.path.exists(img_path):
            os.remove(img_path)
        # 删除缩略图
        thumb_path = os.path.join(current_app.config['UPLOAD_FOLDER_ROOT'],
                                  image.url.replace('photo', 'thumb'))
        if os.path.exists(thumb_path):
            os.remove(thumb_path)
        image.delete()
        return HTTP.OK(data=serializer.data) 
开发者ID:honmaple,项目名称:maple-file,代码行数:21,代码来源:router.py

示例10: get_user_posts

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import config [as 别名]
def get_user_posts(id):
    user = User.query.get_or_404(id)
    page = request.args.get('page', 1, type=int)
    pagination = user.posts.order_by(Post.timestamp.desc()).paginate(
        page, per_page=current_app.config['POSTS_PER_PAGE'],
        error_out=False)
    posts = pagination.items
    prev = None
    if pagination.has_prev:
        prev = url_for('api.get_user_posts', page=page-1, _external=True)
    next = None
    if pagination.has_next:
        next = url_for('api.get_user_posts', page=page+1, _external=True)
    return jsonify({
        'posts': [post.to_json() for post in posts],
        'prev': prev,
        'next': next,
        'count': pagination.total
    }) 
开发者ID:Blackyukun,项目名称:Simpleblog,代码行数:21,代码来源:users.py

示例11: get_user_followed_posts

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import config [as 别名]
def get_user_followed_posts(id):
    user = User.query.get_or_404(id)
    page = request.args.get('page', 1, type=int)
    pagination = user.followed_posts.order_by(Post.timestamp.desc()).paginate(
        page, per_page=current_app.config['POSTS_PER_PAGE'],
        error_out=False)
    posts = pagination.items
    prev = None
    if pagination.has_prev:
        prev = url_for('api.get_user_followed_posts', page=page-1,
                       _external=True)
    next = None
    if pagination.has_next:
        next = url_for('api.get_user_followed_posts', page=page+1,
                       _external=True)
    return jsonify({
        'posts': [post.to_json() for post in posts],
        'prev': prev,
        'next': next,
        'count': pagination.total
    }) 
开发者ID:Blackyukun,项目名称:Simpleblog,代码行数:23,代码来源:users.py

示例12: get_post_comments

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import config [as 别名]
def get_post_comments(id):
    post = Post.query.get_or_404(id)
    page = request.args.get('page', 1, type=int)
    pagination = post.comments.order_by(Comment.timestamp.asc()).paginate(
        page, per_page=current_app.config['COMMENTS_PER_PAGE'],
        error_out=False)
    comments = pagination.items
    prev = None
    if pagination.has_prev:
        prev = url_for('api.get_post_comments', id=id, page=page-1,
                       _external=True)
    next = None
    if pagination.has_next:
        next = url_for('api.get_post_comments', id=id, page=page+1,
                       _external=True)
    return jsonify({
        'comments': [comment.to_json() for comment in comments],
        'prev': prev,
        'next': next,
        'count': pagination.total
    }) 
开发者ID:Blackyukun,项目名称:Simpleblog,代码行数:23,代码来源:comments.py

示例13: get_posts

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import config [as 别名]
def get_posts():
    # posts = Post.query.all()
    # return jsonify({'posts': [post.to_json() for post in posts]})
    page = request.args.get('page', 1, type=int)
    pagination = Post.query.paginate(
        page, per_page=current_app.config['POSTS_PER_PAGE'],
        error_out=False
    )
    posts = pagination.items
    prev = None
    if pagination.has_prev:
        prev = url_for('api.get_posts', page=page-1, _external=True)
    next = None
    if pagination.has_next:
        next = url_for('api.get_posts', page=page+1, _external=True)
    return jsonify({
        'posts': [post.to_json() for post in posts],
        'prev': prev,
        'next': next,
        'count': pagination.total
    }) 
开发者ID:Blackyukun,项目名称:Simpleblog,代码行数:23,代码来源:posts.py

示例14: get_versions

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import config [as 别名]
def get_versions() -> dict:
    """Return available versions

    The configuration stores a dict of versions containing additional
    information like public signing key and upstream path.

    Returns:
        dict: latest available version per branch
    """
    if "versions" not in g:
        g.versions = dict(
            map(
                lambda b: (b["name"], b),
                filter(
                    lambda b: b.get("enabled"),
                    current_app.config["VERSIONS"]["branches"],
                ),
            )
        )
        current_app.logger.info(f"Loaded {len(g.versions)} versions")
    return g.versions 
开发者ID:aparcar,项目名称:asu,代码行数:23,代码来源:api.py

示例15: index

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import config [as 别名]
def index():
    """
    This is not served anywhere in the web application.
    It is used explicitly in the context of generating static files since
    flask-frozen requires url_for's to crawl content.
    url_for's are not used with result.show_result directly and are instead
    dynamically generated through javascript for performance purposes.
    """
    if current_app.config['ARA_PLAYBOOK_OVERRIDE'] is not None:
        override = current_app.config['ARA_PLAYBOOK_OVERRIDE']
        results = (models.TaskResult.query
                   .join(models.Task)
                   .filter(models.Task.playbook_id.in_(override)))
    else:
        results = models.TaskResult.query.all()

    return render_template('task_result_index.html', results=results) 
开发者ID:dmsimard,项目名称:ara-archive,代码行数:19,代码来源:result.py


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