本文整理匯總了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
示例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()
示例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)
示例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
})
示例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
})
示例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
})
示例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
})
示例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
})
示例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)
示例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
})
示例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
})
示例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
})
示例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
})
示例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
示例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)