本文整理汇总了Python中django.utils.six.moves.urllib.parse.urlunparse方法的典型用法代码示例。如果您正苦于以下问题:Python parse.urlunparse方法的具体用法?Python parse.urlunparse怎么用?Python parse.urlunparse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.six.moves.urllib.parse
的用法示例。
在下文中一共展示了parse.urlunparse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: redirect_to_login
# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urlunparse [as 别名]
def redirect_to_login(next, login_url=None,
redirect_field_name=REDIRECT_FIELD_NAME):
"""
Redirects the user to the login page, passing the given 'next' page
"""
resolved_url = resolve_url(login_url or settings.LOGIN_URL)
login_url_parts = list(urlparse(resolved_url))
if redirect_field_name:
querystring = QueryDict(login_url_parts[4], mutable=True)
querystring[redirect_field_name] = next
login_url_parts[4] = querystring.urlencode(safe='/')
return HttpResponseRedirect(urlunparse(login_url_parts))
# 4 views for password reset:
# - password_reset sends the mail
# - password_reset_done shows a success message for the above
# - password_reset_confirm checks the link the user clicked and
# prompts for a new password
# - password_reset_complete shows a success message for the above
示例2: add_preserved_filters
# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urlunparse [as 别名]
def add_preserved_filters(context, url, popup=False, to_field=None):
opts = context.get('opts')
preserved_filters = context.get('preserved_filters')
parsed_url = list(urlparse(url))
parsed_qs = dict(parse_qsl(parsed_url[4]))
merged_qs = dict()
if opts and preserved_filters:
preserved_filters = dict(parse_qsl(preserved_filters))
match_url = '/%s' % url.partition(get_script_prefix())[2]
try:
match = resolve(match_url)
except Resolver404:
pass
else:
current_url = '%s:%s' % (match.app_name, match.url_name)
changelist_url = 'admin:%s_%s_changelist' % (opts.app_label, opts.model_name)
if changelist_url == current_url and '_changelist_filters' in preserved_filters:
preserved_filters = dict(parse_qsl(preserved_filters['_changelist_filters']))
merged_qs.update(preserved_filters)
if popup:
from django.contrib.admin.options import IS_POPUP_VAR
merged_qs[IS_POPUP_VAR] = 1
if to_field:
from django.contrib.admin.options import TO_FIELD_VAR
merged_qs[TO_FIELD_VAR] = to_field
merged_qs.update(parsed_qs)
parsed_url[4] = urlencode(merged_qs)
return urlunparse(parsed_url)
示例3: url_to_template
# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urlunparse [as 别名]
def url_to_template(self, view_name, request, template_name):
resolver = urlresolvers.get_resolver(None)
info = resolver.reverse_dict[view_name]
path_template = info[0][0][0]
# FIXME: what happens when URL has more than one dynamic values?
# e.g. nested relations: manufacturer/%(id)s/cars/%(card_id)s
path = path_template % {info[0][0][1][0]: '{%s}' % template_name}
parsed_url = urlparse(request.build_absolute_uri())
return urlunparse(
[parsed_url.scheme, parsed_url.netloc, path, '', '', '']
)