Here are the examples of the python api django.conf.settings.STATIC_URL taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
157 Examples
3
Example 1
Project: django-sellmo Source File: links.py
def _get_context(**context):
site = Site.objects.get_current()
context.update({
'settings': settings_manager,
'request' : {
'site' : site,
},
'url': 'http://{0}'.format(site.domain),
'prefix': 'http://{0}'.format(site.domain),
'STATIC_URL': 'http://{0}{1}'.format(site.domain, settings.STATIC_URL),
'MEDIA_URL': 'http://{0}{1}'.format(site.domain, settings.MEDIA_URL),
})
return context
3
Example 2
@register.simple_tag
def admin_static_url():
"""
If set, returns the string contained in the setting ADMIN_MEDIA_PREFIX, otherwise returns STATIC_URL + 'admin/'.
"""
return getattr(settings, 'ADMIN_MEDIA_PREFIX', None) or ''.join([settings.STATIC_URL, 'admin/'])
3
Example 3
def content_view(self, obj):
link_icon = '%simages/icons/external_16x16.png' % settings.STATIC_URL
link = '<a href="%s" title="%s"><img src="%s" alt="External 16x16" title="external 16x16" /></a>' % (
obj.get_content_url(),
obj,
link_icon,
)
return link
3
Example 4
@register.simple_tag
def openid_icon(openid, user):
oid = u"%s" % openid
matches = [u.openid == oid for u in UserOpenidAssociation.objects.filter(user=user)]
if any(matches):
return mark_safe(u'<img src="%s" alt="%s" />' % (
os.path.join(settings.STATIC_URL, "images", "openid-icon.png"),
ugettext("Logged in with OpenID")
))
else:
return u""
3
Example 5
def server_error(request, template_name='500.html'):
"""Always include STATIC_URL into the 500 error"""
from django.http import HttpResponseServerError
t = loader.get_template(template_name)
return HttpResponseServerError(t.render(Context({
'STATIC_URL': settings.STATIC_URL})))
3
Example 6
def get_response(self, request):
response = super(MezzStaticFilesHandler, self).get_response(request)
if response.status_code == 404:
locations = (
(settings.STATIC_URL, settings.STATIC_ROOT),
(settings.MEDIA_URL, settings.MEDIA_ROOT),
)
for url, root in locations:
if request.path.startswith(url):
path = request.path.replace(url, "", 1)
try:
return serve(request, path, docuement_root=root)
except Http404:
# Just return the original 404 response.
pass
return response
3
Example 7
def absolute_path(self, path, prefix=None):
if path.startswith(u'http://') or path.startswith(u'https://') or path.startswith(u'/'):
return path
if prefix is None:
if settings.STATIC_URL is None:
# backwards compatibility
prefix = settings.MEDIA_URL
else:
prefix = settings.STATIC_URL
return urljoin(prefix, path)
3
Example 8
Project: roundware-server Source File: forms.py
def get_formset_media_js():
"""
"""
FORMSET_FULL = settings.STATIC_URL + 'js/jquery.formset.js'
FORMSET_MINIFIED = settings.STATIC_URL + 'rw/js/jquery.formset.min.js'
formset_js_path = FORMSET_FULL if settings.DEBUG else FORMSET_MINIFIED
formset_media_js = (formset_js_path, )
return formset_media_js
3
Example 9
Project: django-fluent-blogs Source File: abstractbase.py
@classmethod
def get_status_column(cls, entry):
# Create a status column, is also reused by templatetags/fluent_blogs_admin_tags.py
status = entry.status
title = next(rec[1] for rec in AbstractEntryBase.STATUSES if rec[0] == status)
icon = next(rec[1] for rec in cls.STATUS_ICONS if rec[0] == status)
return u'<img src="{static_url}{icon}" alt="{title}" title="{title}" />'.format(
static_url=settings.STATIC_URL, icon=icon, title=title)
3
Example 10
def static(request):
"""
Adds static-related context variables to the context.
"""
return {'STATIC_URL': settings.STATIC_URL}
3
Example 11
@register.simple_tag(takes_context=True)
def favorites(context, model, user=None):
user = user or context['user']
has_favorited = user.is_authenticated() and \
model.favorite_set.filter(user=user).exists()
return render_to_string("comments/_favorites.html", {
'thing': model,
'STATIC_URL': settings.STATIC_URL,
'num_favorites': model.favorite_set.count(),
'has_favorited': has_favorited,
'user': user,
})
3
Example 12
Project: vegphilly.com Source File: vegancity_template_tags.py
def graphical_rating(rating):
rating_icons = ('<img class="rating" src="' +
settings.STATIC_URL +
'images/rating-solid.png">') * rating
rating_icons += ('<img class="rating" src="' +
settings.STATIC_URL +
'images/rating-faded.png">') * (4 - rating)
return rating_icons
3
Example 13
@hooks.register('insert_editor_css')
def editor_css():
"""
Add extra CSS files to the admin
"""
css_files = [
'wagtailadmin/css/admin.css',
]
css_includes = format_html_join(
'\n', '<link rel="stylesheet" href="{0}{1}">', ((settings.STATIC_URL, filename) for filename in css_files))
return css_includes
3
Example 14
def listicon(icon_name):
"""Tag is used to pass icon style in link
>>> listicon('eye')
'style="text-decoration:none;list-style-image:url(/static/cdr-stats/icons/test.png);"'
"""
return 'style="text-decoration:none;list-style-image:url(%scdr-stats/icons/%s.png);"'\
% (settings.STATIC_URL, icon_name)
3
Example 15
Project: django-thumbor Source File: __init__.py
def _prepend_static_url(url):
if conf.THUMBOR_STATIC_ENABLED and url.startswith(settings.STATIC_URL):
url = _remove_prefix(url, settings.STATIC_URL)
url.lstrip('/')
return '%s/%s' % (conf.THUMBOR_STATIC_URL, url)
return url
3
Example 16
@hooks.register('insert_editor_js')
def editor_js():
# Add extra JS files to the admin
js_files = [
'js/hallo-custom.js',
]
js_includes = format_html_join(
'\n', '<script src="{0}{1}"></script>',
((settings.STATIC_URL, filename) for filename in js_files)
)
return js_includes + format_html(
"""
<script>
registerHalloPlugin('blockquotebutton');
registerHalloPlugin('blockquotebuttonwithclass');
</script>
"""
)
3
Example 17
Project: djangocodemirror Source File: djangocodemirror_tags.py
def render_asset_html(self, path, tag_template):
"""
Render HTML tag for a given path.
Arguments:
path (string): Relative path from static directory.
tag_template (string): Template string for HTML tag.
Returns:
string: HTML tag with url from given path.
"""
url = os.path.join(settings.STATIC_URL, path)
return tag_template.format(url=url)
3
Example 18
Project: tapiriik Source File: email.py
def generate_message_from_template(template, context):
context["STATIC_URL"] = settings.STATIC_URL
# Mandrill is set up to inline the CSS and generate a plaintext copy.
html_message = get_template(template).render(Context(context)).strip()
context["plaintext"] = True
plaintext_message = get_template(template).render(Context(context)).strip()
return html_message, plaintext_message
3
Example 19
def media(self, form):
"""
Collects admin and form media.
"""
js = ['admin/js/core.js', 'admin/js/admin/RelatedObjectLookups.js',
'admin/js/jquery.min.js', 'admin/js/jquery.init.js']
media = forms.Media(
js=['%s%s' % (settings.STATIC_URL, u) for u in js],
)
if form:
for name, field in form.fields.iteritems():
media = media + field.widget.media
return media
3
Example 20
Project: django-cumulus Source File: context_processors.py
def static_cdn_url(request):
"""
A context processor that exposes the full static CDN URL
as static URL in templates.
"""
cdn_url, ssl_url = _get_container_urls(CumulusStaticStorage())
static_url = settings.STATIC_URL
return {
"STATIC_URL": cdn_url + static_url,
"STATIC_SSL_URL": ssl_url + static_url,
"LOCAL_STATIC_URL": static_url,
}
3
Example 21
@hooks.register('insert_editor_css')
def editor_css():
css_files = [
'global/font-awesome/css/font-awesome.css',
'global/css/wagtail-admin.css',
]
css_includes = format_html_join(
'\n',
'<link rel="stylesheet" href="{0}{1}">',
((settings.STATIC_URL, filename) for filename in css_files)
)
return css_includes
3
Example 22
def get_logo_url(self):
"""
Returns the image containing the mugshot for the user.
The mugshot can be a uploaded image or a Gravatar.
:return:
``None`` when no default image is supplied by ``PROJECT_LOGO_DEFAULT``.
"""
# First check for a uploaded logo image and if any return that.
if self.logo:
return self.logo.url
# Check for a default image.
elif getattr(settings, 'PROJECT_LOGO_DEFAULT', None):
return os.path.join(settings.STATIC_URL, settings.PROJECT_LOGO_DEFAULT)
else:
return None
3
Example 23
def absolute_path(self, path, prefix=None):
if path.startswith(('http://', 'https://', '/')):
return path
if prefix is None:
if settings.STATIC_URL is None:
# backwards compatibility
prefix = settings.MEDIA_URL
else:
prefix = settings.STATIC_URL
return urljoin(prefix, path)
3
Example 24
def __init__(self, *args, **kwargs):
image = kwargs.pop('image')
if not image: raise ImproperlyConfigured
super(ImageHeadColumn, self).__init__(*args, **kwargs)
self.header = mark_safe('<img src="%s" alt="%s">'
%(settings.STATIC_URL+image, self.header))
3
Example 25
Project: django-systemjs Source File: test_templatetags.py
@override_settings(SYSTEMJS_ENABLED=True, SYSTEMJS_OUTPUT_DIR='SJ')
def test_script_tag_attributes(self):
template = """{% load system_tags %}{% systemjs_import 'myapp/main' async foo="bar" %}"""
template = django_engine.from_string(template)
rendered = template.render(self.context)
expected_url = urljoin(settings.STATIC_URL, 'SJ/myapp/main.js')
self.assertHTMLEqual(
rendered,
"""<script async foo="bar" type="text/javascript" src="{0}"></script>""".format(expected_url)
)
3
Example 26
def __init__(self):
self.fontname = 'nodewatcher'
self.cssprefix = 'nw'
self.cssname = 'icons.css'
self.fontpath = 'frontend/fonts'
self.csspath = 'frontend/css'
self.fonturl = settings.STATIC_URL + 'frontend/fonts/'
3
Example 27
Project: vegphilly.com Source File: template_tags.py
def test_graphical_rating(self):
rating = 3
img_class_src = '<img class="rating" src="' + settings.STATIC_URL
result_markup = ''.join((
img_class_src + 'images/rating-solid.png">',
img_class_src + 'images/rating-solid.png">',
img_class_src + 'images/rating-solid.png">',
img_class_src + 'images/rating-faded.png">'
))
self.assertEqual(graphical_rating(rating), result_markup)
3
Example 28
Project: splunk-webframework Source File: basehttp.py
def __init__(self, *args, **kwargs):
from django.conf import settings
self.admin_static_prefix = urljoin(settings.STATIC_URL, 'admin/')
# We set self.path to avoid crashes in log_message() on unsupported
# requests (like "OPTIONS").
self.path = ''
self.style = color_style()
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
3
Example 29
Project: django-dockit Source File: inlines.py
def _media(self):
from django.conf import settings
js = ['js/jquery.min.js', 'js/jquery.init.js', 'js/inlines.min.js']
if self.prepopulated_fields:
js.append('js/urlify.js')
js.append('js/prepopulate.min.js')
if self.filter_vertical or self.filter_horizontal:
js.extend(['js/SelectBox.js' , 'js/SelectFilter2.js'])
media = forms.Media(js=['%s%s' % (getattr(settings, 'ADMIN_MEDIA_PREFIX', 'admin'), url) for url in js])
media.add_js(['%sadmin/js/primitivelist.js' % settings.STATIC_URL])
media.add_css({'all': ['%sadmin/css/primitivelist.css' % settings.STATIC_URL]})
return media
3
Example 30
def fetch_resources(uri, rel):
"""
Callback to allow pisa/reportlab to retrieve Images,Stylesheets, etc.
`uri` is the href attribute from the html link element.
`rel` gives a relative path, but it's not used here.
"""
if settings.STATIC_URL in uri:
path = os.path.join(settings.STATIC_ROOT, uri.replace(settings.STATIC_URL, ""))
else:
path = os.path.join(settings.MEDIA_ROOT, uri.replace(settings.MEDIA_URL, ""))
return path
3
Example 31
def icon(icon_name):
"""Tag is used to create icon link
>>> icon('test')
'class="icon" style="text-decoration:none;background-image:url(/static/cdr-stats/icons/test.png);"'
"""
return 'class="icon" style="text-decoration:none;background-image:url(%scdr-stats/icons/%s.png);"'\
% (settings.STATIC_URL, icon_name)
3
Example 32
@hooks.register('insert_editor_js')
def editor_js():
"""
Add extra JS files to the admin
"""
js_files = [
'wagtailadmin/js/vendor/jquery.htmlClean.min.js',
'wagtailadmin/js/vendor/rangy-selectionsaverestore.js',
]
js_includes = format_html_join(
'\n', '<script src="{0}{1}"></script>', ((settings.STATIC_URL, filename) for filename in js_files))
return js_includes + """<script type="text/javascript">
3
Example 33
def check_settings(base_url=None):
"""
Checks if the staticfiles settings have sane values.
"""
if base_url is None:
base_url = settings.STATIC_URL
if not base_url:
raise ImproperlyConfigured(
"You're using the staticfiles app "
"without having set the required STATIC_URL setting.")
if settings.MEDIA_URL == base_url:
raise ImproperlyConfigured("The MEDIA_URL and STATIC_URL "
"settings must have different values")
if ((settings.MEDIA_ROOT and settings.STATIC_ROOT) and
(settings.MEDIA_ROOT == settings.STATIC_ROOT)):
raise ImproperlyConfigured("The MEDIA_ROOT and STATIC_ROOT "
"settings must have different values")
3
Example 34
def absolute_path(self, path, prefix=None):
if path.startswith(('http://', 'https://', '/')):
return path
if prefix is None:
if settings.STATIC_URL is None:
# backwards compatibility
prefix = settings.MEDIA_URL
else:
prefix = settings.STATIC_URL
return urljoin(prefix, path)
3
Example 35
def _get_context(**context):
site = Site.objects.get_current()
context.update({
'settings': settings_manager
'request' : {
'site' : site,
},
'url': 'http://{0}'.format(site.domain),
'prefix': 'http://{0}'.format(site.domain),
'STATIC_URL': 'http://{0}{1}'.format(site.domain, settings.STATIC_URL),
'MEDIA_URL': 'http://{0}{1}'.format(site.domain, settings.MEDIA_URL),
})
return context
3
Example 36
def server_error(request, template_name='500.html'):
""" needed for rendering 500 pages with style. """
t = loader.get_template(template_name)
return http.HttpResponseServerError(t.render(Context({
'request': request,
'STATIC_URL': settings.STATIC_URL,
})))
3
Example 37
@hooks.register('insert_editor_css')
def editor_css():
# Add extra CSS files to the admin like font-awesome
css_files = [
'libs/font-awesome/css/font-awesome.min.css'
]
css_includes = format_html_join(
'\n', '<link rel="stylesheet" href="{0}{1}">',
((settings.STATIC_URL, filename) for filename in css_files)
)
return css_includes
3
Example 38
def render_to_response(self, context, **response_kwargs):
context.update(response_kwargs)
context.update({
"STATIC_URL": settings.STATIC_URL,
"MEDIA_URL": settings.MEDIA_URL,
})
logger.debug(context)
return HttpResponse(self.render_to_pdf(context), mimetype='application/pdf')
3
Example 39
@register.inclusion_tag("feedback_form/form.html")
def feedback():
"""
Sets context variable field given as a parameter to tag.
"""
form = forms.FeedbackForm()
return {
'feedback_form': form,
'STATIC_URL': settings.STATIC_URL
}
3
Example 40
Project: tendenci Source File: admin.py
def rendered_view(self, obj):
link_icon = '%simages/icons/external_16x16.png' % settings.STATIC_URL
link = '<a href="%s" title="%s"><img src="%s" alt="External 16x16" title="external 16x16" /></a>' % (
obj.get_absolute_url(),
obj,
link_icon,
)
return link
3
Example 41
Project: django-crocodile Source File: crocodile.py
def _get_local_file(self, filename):
stripped_filename = filename.replace(settings.STATIC_URL, "").replace(settings.MEDIA_URL, "")
r = FileSystemFinder().find(stripped_filename)
if not r:
r = AppDirectoriesFinder().find(stripped_filename)
if not r:
logging.warn("[django-crocodile] File not found: %s" % filename)
return ""
return open(r).read().decode("utf-8", "replace") + "\n"
3
Example 42
def staticfiles_urlpatterns(prefix=None):
"""
Helper function to return a URL pattern for serving static files.
"""
if prefix is None:
prefix = settings.STATIC_URL
return static(prefix, view='django.contrib.staticfiles.views.serve')
3
Example 43
Project: django-cumulus Source File: context_processors.py
def cdn_url(request):
"""
A context processor that exposes the full CDN URL in templates.
"""
cdn_url, ssl_url = _get_container_urls(CumulusStorage())
static_url = settings.STATIC_URL
return {
"CDN_URL": cdn_url + static_url,
"CDN_SSL_URL": ssl_url + static_url,
}
3
Example 44
def view_on_site(self, obj):
link_icon = '%simages/icons/external_16x16.png' % settings.STATIC_URL
link = '<a href="%s" title="%s"><img src="%s" alt="%s" title="%s" /></a>' % (
reverse('page', args=[obj.slug]),
obj.title,
link_icon,
obj.title,
obj.title
)
return link
3
Example 45
def staticfiles_urlpatterns(prefix=None):
"""
Helper function to return a URL pattern for serving static files.
"""
if prefix is None:
prefix = settings.STATIC_URL
return static(prefix, view=serve)
3
Example 46
Project: pinax-ratings Source File: pinax_ratings_tags.py
@register.inclusion_tag("pinax/ratings/_script.html")
def user_rating_js(user, obj, category=None):
post_url = rating_post_url(user, obj)
rating = user_rating_value(user, obj, category)
return {
"obj": obj,
"post_url": post_url,
"category": category,
"the_user_rating": rating,
"STATIC_URL": settings.STATIC_URL,
}
3
Example 47
def check_settings(base_url=None):
"""
Checks if the staticfiles settings have sane values.
"""
if base_url is None:
base_url = settings.STATIC_URL
if not base_url:
raise ImproperlyConfigured(
"You're using the staticfiles app "
"without having set the required STATIC_URL setting.")
if settings.MEDIA_URL == base_url:
raise ImproperlyConfigured("The MEDIA_URL and STATIC_URL "
"settings must have different values")
if ((settings.MEDIA_ROOT and settings.STATIC_ROOT) and
(settings.MEDIA_ROOT == settings.STATIC_ROOT)):
raise ImproperlyConfigured("The MEDIA_ROOT and STATIC_ROOT "
"settings must have different values")
3
Example 48
Project: django-uni-form Source File: uni_form_filters.py
@register.inclusion_tag("uni_form/includes.html", takes_context=True)
def uni_form_setup(context):
"""
Creates the `<style>` and `<script>` tags needed to initialize uni-form.
You can create a local uni-form/includes.html template if you want to customize how
these files are loaded.
Only works with Django 1.3+
"""
if 'STATIC_URL' not in context:
context['STATIC_URL'] = settings.STATIC_URL
return (context)
3
Example 49
Project: shuup Source File: plugins.py
def add_resources(context, content):
view_class = getattr(context["view"], "__class__", None) if context.get("view") else None
if not view_class:
return
view_name = getattr(view_class, "__name__", "")
if view_name == "ProductDetailView":
add_resource(context, "body_end", "%sshuup/recently_viewed_products/lib.js" % settings.STATIC_URL)
3
Example 50
def index(request):
""" Updates the visited count and provides the static URL to build the main
landing page.
"""
logging.info("in the index view")
visited = __update_visited()
context = {
"STATIC_URL": settings.STATIC_URL,
"visited": visited
}
return render(request, 'index.html', context)