我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用django.utils.html.smart_urlquote()。
def render(self, name, value, attrs=None): if value is None: return format_html( '<p class="text-error">{text}</p>', text=_('Populate form fields above'), ) final_attrs = self.build_attrs(attrs) href = smart_urlquote(value) text = self.text or href return format_html( '<p><a href="{href}" {attrs}>{text}</a></p>', href=href, attrs=flatatt(final_attrs), text=force_str(text), )
def render(self, name, value, attrs=None): html = super(AdminURLFieldWidget, self).render(name, value, attrs) if value: value = force_text(self.format_value(value)) final_attrs = {'href': smart_urlquote(value)} html = format_html( '<p class="url">{} <a{}>{}</a><br />{} {}</p>', _('Currently:'), flatatt(final_attrs), value, _('Change:'), html ) return html
def get_context(self, name, value, attrs): context = super(AdminURLFieldWidget, self).get_context(name, value, attrs) context['current_label'] = _('Currently:') context['change_label'] = _('Change:') context['widget']['href'] = smart_urlquote(context['widget']['value']) if value else '' return context
def smart_urlquote_wrapper(matched_url): """ Simple wrapper for smart_urlquote. ValueError("Invalid IPv6 URL") can be raised here, see issue #1386 """ try: return smart_urlquote(matched_url) except ValueError: return None
def render(self, name, value, attrs=None): if value is None: return None final_attrs = self.build_attrs(attrs) href = smart_urlquote(value) text = self.text or href return format_html( '<a href="{href}" {attrs}>{text}</a>', href=href, attrs=flatatt(final_attrs), text=force_str(text), )
def append(value): if value: output = '<a href="{href}" class="add-on" target="_blank"><i class="icon-globe"></i></a>' href = force_str(value) return format_html(output, href=smart_urlquote(href)) else: output = '<span class="add-on"><i class="icon-globe"></i></span>' return format_html(output)
def render(self, name, value, attrs=None): html = super(AdminURLFieldWidget, self).render(name, value, attrs) if value: value = force_text(self._format_value(value)) final_attrs = {'href': smart_urlquote(value)} html = format_html( '<p class="url">{0} <a{1}>{2}</a><br />{3} {4}</p>', _('Currently:'), flatatt(final_attrs), value, _('Change:'), html ) return html