本文整理汇总了Python中django.contrib.staticfiles.storage.staticfiles_storage.url方法的典型用法代码示例。如果您正苦于以下问题:Python staticfiles_storage.url方法的具体用法?Python staticfiles_storage.url怎么用?Python staticfiles_storage.url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.staticfiles.storage.staticfiles_storage
的用法示例。
在下文中一共展示了staticfiles_storage.url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: environment
# 需要导入模块: from django.contrib.staticfiles.storage import staticfiles_storage [as 别名]
# 或者: from django.contrib.staticfiles.storage.staticfiles_storage import url [as 别名]
def environment(**options: Any) -> Environment:
env = Environment(**options)
env.globals.update({
'default_page_params': {
'debug_mode': False,
'webpack_public_path': staticfiles_storage.url(
settings.WEBPACK_LOADER['DEFAULT']['BUNDLE_DIR_NAME'],
),
},
'static': staticfiles_storage.url,
'url': reverse,
'render_markdown_path': render_markdown_path,
})
env.install_gettext_translations(translation, True)
env.filters['slugify'] = slugify
env.filters['pluralize'] = pluralize
env.filters['display_list'] = display_list
env.filters['device_action'] = device_action
env.filters['timesince'] = timesince
return env
示例2: environment
# 需要导入模块: from django.contrib.staticfiles.storage import staticfiles_storage [as 别名]
# 或者: from django.contrib.staticfiles.storage.staticfiles_storage import url [as 别名]
def environment(**options):
env = Environment(**options)
env.globals.update({
'static': loudfail_static,
'url': reverse,
"content": "project.content.constants",
"linkify": "project.jinja2.linkify",
"current_local_time": "project.jinja2.current_local_time",
"namify": "project.jinja2.namify",
"url_with_ids": "project.jinja2.url_with_ids",
"oxford_comma": "project.jinja2.oxford_comma",
"contact_info_to_html": "project.jinja2.contact_info_to_html",
"to_json": "project.jinja2.to_json",
"humanize": "project.jinja2.humanize",
"contact_method_verbs": "project.jinja2.contact_method_verbs",
"format_phone_number": "project.jinja2.format_phone_number",
"settings": "django.conf.settings",
"local_time": "intake.utils.local_time",
})
return env
示例3: test_body_encoding_with_imgDisplay
# 需要导入模块: from django.contrib.staticfiles.storage import staticfiles_storage [as 别名]
# 或者: from django.contrib.staticfiles.storage.staticfiles_storage import url [as 别名]
def test_body_encoding_with_imgDisplay(self):
self.user.inboxenprofile.display_images = models.UserProfile.ASK
self.user.inboxenprofile.save()
response = self.client.get(self.get_url() + "?imgDisplay=1")
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context["email"]["bodies"]), 1)
self.assertFalse(response.context["email"]["ask_images"] and response.context["email"]["has_images"])
body = response.context["email"]["bodies"][0]
self.assertIn(u"<p style=\"color:#fff\"> </p>", body)
self.assertIn(u"<p style=\"color:#fff\">£££</p>", body)
self.assertIn(u"http://example.com/coolface.jpg", body)
self.assertIn(u"img width=\"10\" height=\"10\"", body)
self.assertNotIn(staticfiles_storage.url("imgs/placeholder.svg"), body)
# premailer should have worked fine
self.assertNotIn("Part of this message could not be parsed - it may not display correctly",
response.content.decode("utf-8"))
# csp
self.assertIn("style-src 'self' 'unsafe-inline';", response["content-security-policy"])
self.assertIn("img-src 'self' https:;", response["content-security-policy"])
示例4: test_body_encoding_without_imgDisplay
# 需要导入模块: from django.contrib.staticfiles.storage import staticfiles_storage [as 别名]
# 或者: from django.contrib.staticfiles.storage.staticfiles_storage import url [as 别名]
def test_body_encoding_without_imgDisplay(self):
self.user.inboxenprofile.display_images = models.UserProfile.ASK
self.user.inboxenprofile.save()
response = self.client.get(self.get_url())
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context["email"]["bodies"]), 1)
self.assertTrue(response.context["email"]["ask_images"] and response.context["email"]["has_images"])
body = response.context["email"]["bodies"][0]
self.assertIn(u"<p style=\"color:#fff\"> </p>", body)
self.assertIn(u"<p style=\"color:#fff\">£££</p>", body)
self.assertNotIn(u"http://example.com/coolface.jpg", body)
self.assertIn(u"img width=\"10\" height=\"10\"", body)
self.assertIn(staticfiles_storage.url("imgs/placeholder.svg"), body)
# premailer should have worked fine
self.assertNotIn("Part of this message could not be parsed - it may not display correctly",
response.content.decode("utf-8"))
# csp
self.assertIn("style-src 'self' 'unsafe-inline';", response["content-security-policy"])
self.assertIn("img-src 'self';", response["content-security-policy"])
self.assertNotIn("img-src 'self' https:;", response["content-security-policy"])
示例5: test_body_no_ask_images
# 需要导入模块: from django.contrib.staticfiles.storage import staticfiles_storage [as 别名]
# 或者: from django.contrib.staticfiles.storage.staticfiles_storage import url [as 别名]
def test_body_no_ask_images(self):
self.user.inboxenprofile.display_images = models.UserProfile.NO_DISPLAY
self.user.inboxenprofile.save()
response = self.client.get(self.get_url())
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context["email"]["bodies"]), 1)
self.assertFalse(response.context["email"]["ask_images"] and response.context["email"]["has_images"])
body = response.context["email"]["bodies"][0]
self.assertIn(u"<p style=\"color:#fff\"> </p>", body)
self.assertIn(u"<p style=\"color:#fff\">£££</p>", body)
self.assertNotIn(u"http://example.com/coolface.jpg", body)
self.assertIn(u"img width=\"10\" height=\"10\"", body)
self.assertIn(staticfiles_storage.url("imgs/placeholder.svg"), body)
# premailer should have worked fine
self.assertNotIn("Part of this message could not be parsed - it may not display correctly",
response.content.decode("utf-8"))
# csp
self.assertIn("style-src 'self' 'unsafe-inline';", response["content-security-policy"])
self.assertIn("img-src 'self';", response["content-security-policy"])
self.assertNotIn("img-src 'self' https:;", response["content-security-policy"])
示例6: test_download
# 需要导入模块: from django.contrib.staticfiles.storage import staticfiles_storage [as 别名]
# 或者: from django.contrib.staticfiles.storage.staticfiles_storage import url [as 别名]
def test_download(self):
url = urls.reverse("download-email-view", kwargs={"email": self.email.eid,
"inbox": self.email.inbox.inbox,
"domain": self.email.inbox.domain.domain})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response["Content-Disposition"],
"attachment; filename={}-{}.mbox".format(str(self.email.inbox), self.email.eid))
self.assertEqual(response["Content-Type"], "application/mbox")
with NamedTemporaryFile() as tmp:
tmp.write(response.content)
tmp.file.flush() # just to be sure
box = mailbox.mbox(tmp.name)
self.assertEqual(len(box), 1)
示例7: test_rate_limit
# 需要导入模块: from django.contrib.staticfiles.storage import staticfiles_storage [as 别名]
# 或者: from django.contrib.staticfiles.storage.staticfiles_storage import url [as 别名]
def test_rate_limit(self):
url = urls.reverse("download-email-view", kwargs={"email": self.email.eid,
"inbox": self.email.inbox.inbox,
"domain": self.email.inbox.domain.domain})
request = MockRequest(user=self.user)
for i in range(settings.SINGLE_EMAIL_LIMIT_COUNT - 1):
ratelimit.single_email_ratelimit.counter_increase(request)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
cache.cache.clear()
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
示例8: static
# 需要导入模块: from django.contrib.staticfiles.storage import staticfiles_storage [as 别名]
# 或者: from django.contrib.staticfiles.storage.staticfiles_storage import url [as 别名]
def static(path):
return staticfiles_storage.url(path)
示例9: url
# 需要导入模块: from django.contrib.staticfiles.storage import staticfiles_storage [as 别名]
# 或者: from django.contrib.staticfiles.storage.staticfiles_storage import url [as 别名]
def url(self, context):
path = self.path.resolve(context)
return static(path)
示例10: url
# 需要导入模块: from django.contrib.staticfiles.storage import staticfiles_storage [as 别名]
# 或者: from django.contrib.staticfiles.storage.staticfiles_storage import url [as 别名]
def url(self, context):
path = self.path.resolve(context)
return self.handle_simple(path)
示例11: render
# 需要导入模块: from django.contrib.staticfiles.storage import staticfiles_storage [as 别名]
# 或者: from django.contrib.staticfiles.storage.staticfiles_storage import url [as 别名]
def render(self, context):
url = self.url(context)
if context.autoescape:
url = conditional_escape(url)
if self.varname is None:
return url
context[self.varname] = url
return ''
示例12: handle_simple
# 需要导入模块: from django.contrib.staticfiles.storage import staticfiles_storage [as 别名]
# 或者: from django.contrib.staticfiles.storage.staticfiles_storage import url [as 别名]
def handle_simple(cls, path):
if apps.is_installed('django.contrib.staticfiles'):
from django.contrib.staticfiles.storage import staticfiles_storage
return staticfiles_storage.url(path)
else:
return urljoin(PrefixNode.handle_simple("STATIC_URL"), quote(path))
示例13: get_logo_url
# 需要导入模块: from django.contrib.staticfiles.storage import staticfiles_storage [as 别名]
# 或者: from django.contrib.staticfiles.storage.staticfiles_storage import url [as 别名]
def get_logo_url(self) -> Optional[str]:
if self.logo_path is not None:
return staticfiles_storage.url(self.logo_path)
return None
示例14: __init__
# 需要导入模块: from django.contrib.staticfiles.storage import staticfiles_storage [as 别名]
# 或者: from django.contrib.staticfiles.storage.staticfiles_storage import url [as 别名]
def __init__(self, name: str, categories: List[str], logo: Optional[str]=None,
secondary_line_text: Optional[str]=None, display_name: Optional[str]=None,
doc: Optional[str]=None) -> None:
super().__init__(
name,
client_name=name,
categories=categories,
secondary_line_text=secondary_line_text,
)
if logo is None:
self.logo_url = self.get_logo_url()
if self.logo_url is None:
# TODO: Add a test for this by initializing one in a test.
logo = staticfiles_storage.url(self.ZULIP_LOGO_STATIC_PATH_PNG) # nocoverage
else:
self.logo_url = staticfiles_storage.url(logo)
if display_name is None:
display_name = f"{name.title()} Bot" # nocoverage
else:
display_name = f"{display_name} Bot"
self.display_name = display_name
if doc is None:
doc = self.DEFAULT_DOC_PATH.format(name=name)
self.doc = doc
示例15: url_object
# 需要导入模块: from django.contrib.staticfiles.storage import staticfiles_storage [as 别名]
# 或者: from django.contrib.staticfiles.storage.staticfiles_storage import url [as 别名]
def url_object(self) -> RegexPattern:
return url(self.url, self.function)