本文整理汇总了Python中flask.request.base_url方法的典型用法代码示例。如果您正苦于以下问题:Python request.base_url方法的具体用法?Python request.base_url怎么用?Python request.base_url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.request
的用法示例。
在下文中一共展示了request.base_url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_url
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import base_url [as 别名]
def to_url(self, url=None, replace=False, **kwargs):
'''Serialize the query into an URL'''
params = copy.deepcopy(self.filter_values)
if self._query:
params['q'] = self._query
if self.page_size != DEFAULT_PAGE_SIZE:
params['page_size'] = self.page_size
if kwargs:
for key, value in kwargs.items():
if not replace and key in params:
if not isinstance(params[key], (list, tuple)):
params[key] = [params[key], value]
else:
params[key].append(value)
else:
params[key] = value
else:
params['page'] = self.page
href = Href(url or request.base_url)
return href(params)
示例2: col_sortable_filter
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import base_url [as 别名]
def col_sortable_filter(context, title, is_alpha=False, id=None):
id = title if id is None else id
id = id.lower()
# when sorting for numbers, we're interested in large numbers first
next_sort = 'asc' if is_alpha else 'desc'
sort_id, sort_order = context.parent.get('sort', 'a_b').split('_')
classes = ['sortable']
if sort_id.lower() == id:
sort_class = 'sort_' + sort_order
next_sort = 'desc' if sort_order == 'asc' else 'asc'
if is_alpha:
sort_class += '_alpha'
classes.append(sort_class)
next_sort = id + '_' + next_sort
# replace/set ?sort= in URL
args = request.args.copy()
args['sort'] = next_sort
url = Href(request.base_url, sort=True)
return '<a href="%s" class="%s">%s</a>' % (url(args), ' '.join(classes), title)
示例3: wrapHttpEndpoint
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import base_url [as 别名]
def wrapHttpEndpoint(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
context = {
"url": request.base_url,
"args": dict(request.args.items()),
"form": dict(request.form.items()),
"body": request.data.decode("utf-8", "strict"),
"headers": dict(request.headers.items()),
"func": request.endpoint,
"ip": request.remote_addr
}
endpoint_name = str(request.url_rule)
wrapped = measure(f, endpoint_name, request.method, context)
return wrapped(*args, **kwargs)
return wrapper
示例4: review
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import base_url [as 别名]
def review(title):
"""
This URL only exists for legacy reasons so try to find the article where
it is in the new scheme and return 301 to indicate moved.
"""
branch = request.args.get('branch', u'master')
article = models.search_for_article(title)
if article is not None:
return redirect(filters.url_for_article(article, branch=branch), 301)
return missing_article(request.base_url, title=title, branch=branch)
# Note this URL is directly linked to the filters.url_for_article filter.
# These must be changed together!
示例5: base_url
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import base_url [as 别名]
def base_url(path = None):
return request.base_url + ("" if path is None else "/" + path)
示例6: forbidden
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import base_url [as 别名]
def forbidden(message="Forbidden."):
log.debug("Response 403: %s", message)
log.info("Forbade %s %s %s: %s", request.remote_addr, request.method, request.base_url, message)
return Response(message + "\n", status=403, mimetype="text/plain")
示例7: not_allowed
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import base_url [as 别名]
def not_allowed():
log.debug("Response 405: %s not allowed.", request.method)
log.info("Disallowed %s %s %s", request.remote_addr, request.method, request.base_url)
return Response("%s not allowed on this resource\n" % (request.method),
status=405, mimetype="text/plain")
示例8: error
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import base_url [as 别名]
def error(message="Unknown internal error"):
log.debug("Response 500: %s", message)
log.error("Internal error %s %s %s: %s", request.remote_addr, request.method, request.base_url, message)
return Response(message + '\n', status=500, mimetype="text/plain")
示例9: not_implemented
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import base_url [as 别名]
def not_implemented(message="Not implemented."):
log.debug("Response 501: %s", message)
log.warning("Not implemented %s %s %s: %s", request.remote_addr, request.method, request.base_url, message)
return Response(message + "\n", status=501, mimetype="text/plain")
示例10: build_cursor_link
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import base_url [as 别名]
def build_cursor_link(self, name, cursor):
querystring = "&".join(
f"{quote(k)}={quote(v)}" for k, v in request.args.items() if k != "cursor"
)
base_url = request.base_url
if querystring:
base_url = f"{base_url}?{querystring}"
else:
base_url = base_url + "?"
return LINK_HEADER.format(uri=base_url, cursor=str(cursor), name=name)
示例11: _get_api_version
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import base_url [as 别名]
def _get_api_version():
url = request.base_url
if 'api' not in url:
return None
version = url.split('/api/')[1]
return version.split('/')[0]
示例12: track_download
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import base_url [as 别名]
def track_download(self, attachment, from_preview, **kwargs):
if from_preview or not self.settings.get('enabled_for_downloads'):
return
if attachment.type == AttachmentType.link:
resource_url = attachment.link_url
resource_title = u'Link - {0.title}'.format(attachment)
else:
resource_url = request.base_url
resource_title = u'Download - {0.title}'.format(attachment)
track_download_request.delay(resource_url, resource_title)
示例13: send_password_recovery_email
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import base_url [as 别名]
def send_password_recovery_email(user, token):
href = request.base_url + '/' + token
send_async_password_recovery_email.delay(subject="Password Recovery by Flask Base Api! %s" % user.username,
recipient=user.email,
text_body=render_template("auth/password_recovery_user.txt", user=user),
html_body=render_template("auth/password_recovery_user.html", user=user, href=href))
示例14: send_email_verification_email
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import base_url [as 别名]
def send_email_verification_email(user, token):
href = request.base_url + '/' + token
send_async_email_verification_email.delay(subject="Email confirmation by Flask Base Api! %s" % user.username,
recipient=user.email,
text_body=render_template("auth/email_verification_user.txt", user=user),
html_body=render_template("auth/email_verification_user.html", user=user, href=href))
示例15: create_link_string
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import base_url [as 别名]
def create_link_string(page, last_page, per_page):
"""Returns a string representing the value of the ``Link`` header.
`page` is the number of the current page, `last_page` is the last page in
the pagination, and `per_page` is the number of results per page.
"""
linkstring = ''
if page < last_page:
next_page = page + 1
linkstring = LINKTEMPLATE.format(request.base_url, next_page,
per_page, 'next') + ', '
linkstring += LINKTEMPLATE.format(request.base_url, last_page,
per_page, 'last')
return linkstring