Python django.conf.settings.STATIC_URL Examples
The following are 30
code examples of django.conf.settings.STATIC_URL().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.conf.settings
, or try the search function
.
Example #1
Source File: static.py From GTDWeb with GNU General Public License v2.0 | 6 votes |
def get_static_prefix(parser, token): """ Populates a template variable with the static prefix, ``settings.STATIC_URL``. Usage:: {% get_static_prefix [as varname] %} Examples:: {% get_static_prefix %} {% get_static_prefix as static_prefix %} """ return PrefixNode.handle_token(parser, token, "STATIC_URL")
Example #2
Source File: utils.py From Hands-On-Application-Development-with-PyCharm with MIT License | 6 votes |
def check_settings(base_url=None): """ Check 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")
Example #3
Source File: emoji.py From BikeMaps with MIT License | 6 votes |
def run(self, lines): new_lines = [] def emojify(match): emoji = match.group(1) if not emoji in emojis_set: return match.group(0) image = emoji + u'.png' url = os.path.join(settings.STATIC_URL, u'spirit', u'emojis', image).replace(u'\\', u'/') return u'![%(emoji)s](%(url)s)' % {'emoji': emoji, 'url': url} for line in lines: if line.strip(): line = re.sub(ur':(?P<emoji>[a-z0-9\+\-_]+):', emojify, line, flags=re.UNICODE) new_lines.append(line) return new_lines
Example #4
Source File: fluent_comments_tags.py From DCRM with GNU Affero General Public License v3.0 | 6 votes |
def get_context_data(self, parent_context, *tag_args, **tag_kwargs): """ The main logic for the inclusion node, analogous to ``@register.inclusion_node``. """ target_object = tag_args[0] # moved one spot due to .pop(0) new_context = { 'STATIC_URL': parent_context.get('STATIC_URL', None), 'USE_THREADEDCOMMENTS': appsettings.USE_THREADEDCOMMENTS, 'target_object': target_object, } # Be configuration independent: if new_context['STATIC_URL'] is None: try: request = parent_context['request'] except KeyError: new_context.update({'STATIC_URL': settings.STATIC_URL}) else: new_context.update(context_processors.static(request)) return new_context
Example #5
Source File: sql_printing_middleware.py From substra-backend with Apache License 2.0 | 6 votes |
def __call__(self, request): response = self.get_response(request) if (len(connection.queries) == 0 or request.path_info.startswith('/favicon.ico') or request.path_info.startswith(settings.STATIC_URL) or request.path_info.startswith(settings.MEDIA_URL)): return response indentation = 2 print(("\n\n%s\033[1;35m[SQL Queries for]\033[1;34m %s\033[0m\n" % (" " * indentation, request.path_info))) total_time = 0.0 for query in connection.queries: if query['sql']: nice_sql = query['sql'].replace('"', '').replace(',', ', ') sql = "\033[1;31m[%s]\033[0m %s" % (query['time'], nice_sql) total_time = total_time + float(query['time']) print(("%s%s\n" % (" " * indentation, sql))) replace_tuple = (" " * indentation, str(total_time), str(len(connection.queries))) print(("%s\033[1;32m[TOTAL TIME: %s seconds (%s queries)]\033[0m" % replace_tuple)) return response
Example #6
Source File: middleware.py From online-judge with GNU Affero General Public License v3.0 | 6 votes |
def __call__(self, request): if request.user.is_authenticated: profile = request.profile = request.user.profile logout_path = reverse('auth_logout') login_2fa_path = reverse('login_2fa') webauthn_path = reverse('webauthn_assert') change_password_path = reverse('password_change') change_password_done_path = reverse('password_change_done') has_2fa = profile.is_totp_enabled or profile.is_webauthn_enabled if (has_2fa and not request.session.get('2fa_passed', False) and request.path not in (login_2fa_path, logout_path, webauthn_path) and not request.path.startswith(settings.STATIC_URL)): return HttpResponseRedirect(login_2fa_path + '?next=' + urlquote(request.get_full_path())) elif (request.session.get('password_pwned', False) and request.path not in (change_password_path, change_password_done_path, login_2fa_path, logout_path) and not request.path.startswith(settings.STATIC_URL)): return HttpResponseRedirect(change_password_path + '?next=' + urlquote(request.get_full_path())) else: request.profile = None return self.get_response(request)
Example #7
Source File: static.py From python with Apache License 2.0 | 6 votes |
def do_static(parser, token): """ Joins the given path with the STATIC_URL setting. Usage:: {% static path [as varname] %} Examples:: {% static "myapp/css/base.css" %} {% static variable_with_path %} {% static "myapp/css/base.css" as admin_base_css %} {% static variable_with_path as varname %} """ return StaticNode.handle_token(parser, token)
Example #8
Source File: mail.py From conf_site with MIT License | 6 votes |
def send_email(to, kind, cc=[], **kwargs): current_site = Site.objects.get_current() ctx = {"current_site": current_site, "STATIC_URL": settings.STATIC_URL} ctx.update(kwargs.get("context", {})) subject = "[%s] %s" % ( current_site.name, render_to_string( "symposion/emails/%s/subject.txt" % kind, ctx ).strip(), ) message_html = render_to_string( "symposion/emails/%s/message.html" % kind, ctx ) message_plaintext = strip_tags(message_html) from_email = settings.DEFAULT_FROM_EMAIL email = EmailMultiAlternatives( subject, message_plaintext, from_email, to, cc=cc ) email.attach_alternative(message_html, "text/html") email.send()
Example #9
Source File: static.py From GTDWeb with GNU General Public License v2.0 | 6 votes |
def do_static(parser, token): """ Joins the given path with the STATIC_URL setting. Usage:: {% static path [as varname] %} Examples:: {% static "myapp/css/base.css" %} {% static variable_with_path %} {% static "myapp/css/base.css" as admin_base_css %} {% static variable_with_path as varname %} """ return StaticNode.handle_token(parser, token)
Example #10
Source File: static.py From Hands-On-Application-Development-with-PyCharm with MIT License | 6 votes |
def do_static(parser, token): """ Join the given path with the STATIC_URL setting. Usage:: {% static path [as varname] %} Examples:: {% static "myapp/css/base.css" %} {% static variable_with_path %} {% static "myapp/css/base.css" as admin_base_css %} {% static variable_with_path as varname %} """ return StaticNode.handle_token(parser, token)
Example #11
Source File: middleware.py From django-spa with MIT License | 6 votes |
def update_files_dictionary(self, *args): super(SPAMiddleware, self).update_files_dictionary(*args) index_page_suffix = '/' + self.index_name index_name_length = len(self.index_name) static_prefix_length = len(settings.STATIC_URL) - 1 directory_indexes = {} for url, static_file in self.files.items(): if url.endswith(index_page_suffix): # For each index file found, add a corresponding URL->content # mapping for the file's parent directory, # so that the index page is served for # the bare directory URL ending in '/'. parent_directory_url = url[:-index_name_length] directory_indexes[parent_directory_url] = static_file # remember the root page for any other unrecognised files # to be frontend-routed self.spa_root = static_file else: # also serve static files on / # e.g. when /my/file.png is requested, serve /static/my/file.png directory_indexes[url[static_prefix_length:]] = static_file self.files.update(directory_indexes)
Example #12
Source File: middleware.py From django-spa with MIT License | 6 votes |
def find_file(self, url): # In debug mode, find_file() is used to serve files directly # from the filesystem instead of using the list in `self.files`, # we append the index filename so that will be served if present. # TODO: handle the trailing slash for the case of e.g. /welcome/ # (should be frontend-routed) if url.endswith('/'): url += self.index_name self.spa_root = super(SPAMiddleware, self).find_file(url) return self.spa_root else: # also serve static files on / # e.g. when /my/file.png is requested, serve /static/my/file.png if (not url.startswith(settings.STATIC_URL)): url = os.path.join(settings.STATIC_URL, url[1:]) return super(SPAMiddleware, self).find_file(url)
Example #13
Source File: static.py From bioforum with MIT License | 6 votes |
def do_static(parser, token): """ Join the given path with the STATIC_URL setting. Usage:: {% static path [as varname] %} Examples:: {% static "myapp/css/base.css" %} {% static variable_with_path %} {% static "myapp/css/base.css" as admin_base_css %} {% static variable_with_path as varname %} """ return StaticNode.handle_token(parser, token)
Example #14
Source File: storage.py From django-tenants with MIT License | 6 votes |
def relative_static_url(self): url = settings.STATIC_URL rewrite_on = False try: if settings.REWRITE_STATIC_URLS is True: rewrite_on = True try: multitenant_relative_url = settings.MULTITENANT_RELATIVE_STATIC_ROOT except AttributeError: # MULTITENANT_RELATIVE_STATIC_ROOT is an optional setting. Use the default of just appending # the tenant schema_name to STATIC_ROOT if no configuration value is provided multitenant_relative_url = "%s" url = "/" + "/".join(s.strip("/") for s in [url, multitenant_relative_url]) + "/" except AttributeError: # REWRITE_STATIC_URLS not set - ignore pass return rewrite_on, url
Example #15
Source File: wagtail_hooks.py From wagtail-cookiecutter-foundation with MIT License | 6 votes |
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> """ )
Example #16
Source File: utils.py From bioforum with MIT License | 6 votes |
def check_settings(base_url=None): """ Check 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")
Example #17
Source File: context.py From coursys with GNU General Public License v3.0 | 6 votes |
def media(request): """ Add context things that we need """ # A/B testing: half of instructors and TAs see a different search box instr_ta = is_instr_ta(request.user.username) instr_ta_ab = instr_ta and request.user.is_authenticated and request.user.id % 2 == 0 # GRAD_DATE(TIME?)_FORMAT for the grad/ra/ta apps return {'GRAD_DATE_FORMAT': settings.GRAD_DATE_FORMAT, 'GRAD_DATETIME_FORMAT': settings.GRAD_DATETIME_FORMAT, 'LOGOUT_URL': settings.LOGOUT_URL, 'LOGIN_URL': settings.LOGIN_URL, 'STATIC_URL': settings.STATIC_URL, 'is_instr_ta': instr_ta, 'instr_ta_ab': instr_ta_ab, 'request_path': request.path, 'CourSys': product_name(request), 'help_email': help_email(request), }
Example #18
Source File: views.py From donation-tracker with Apache License 2.0 | 6 votes |
def index(request, **kwargs): bundle = webpack_manifest.load( os.path.abspath( os.path.join(os.path.dirname(__file__), '../ui-tracker.manifest.json') ), settings.STATIC_URL, debug=settings.DEBUG, timeout=60, read_retry=None, ) return render( request, 'ui/index.html', { 'event': Event.objects.latest(), 'events': Event.objects.all(), 'bundle': bundle.tracker, 'CONSTANTS': mark_safe(json.dumps(constants())), 'ROOT_PATH': reverse('tracker:ui:index'), 'app': 'TrackerApp', 'form_errors': {}, 'props': '{}', }, )
Example #19
Source File: static.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def get_static_prefix(parser, token): """ Populates a template variable with the static prefix, ``settings.STATIC_URL``. Usage:: {% get_static_prefix [as varname] %} Examples:: {% get_static_prefix %} {% get_static_prefix as static_prefix %} """ return PrefixNode.handle_token(parser, token, "STATIC_URL")
Example #20
Source File: profiles.py From GetTogether with BSD 2-Clause "Simplified" License | 5 votes |
def avatar_url(self): try: if ( self.avatar is None or self.avatar.name is None or self.avatar.name == "" ): return settings.STATIC_URL + "img/avatar_placeholder.png" elif self.avatar.name.startswith("http"): return self.avatar.name else: return self.avatar.url except: return settings.STATIC_URL + "img/avatar_placeholder.png"
Example #21
Source File: static.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def get_static_prefix(parser, token): """ Populate a template variable with the static prefix, ``settings.STATIC_URL``. Usage:: {% get_static_prefix [as varname] %} Examples:: {% get_static_prefix %} {% get_static_prefix as static_prefix %} """ return PrefixNode.handle_token(parser, token, "STATIC_URL")
Example #22
Source File: base.py From django-connected with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_avatar_url(self): return settings.STATIC_URL + 'img/connected_accounts/icon-user-default.jpg'
Example #23
Source File: adminx.py From ishare with MIT License | 5 votes |
def block_extrahead(self, context, nodes): js = '<script type="text/javascript" src="%s"></script>' % (settings.STATIC_URL + "ueditor/ueditor.config.js") js += '<script type="text/javascript" src="%s"></script>' % (settings.STATIC_URL + "ueditor/ueditor.all.min.js") nodes.append(js)
Example #24
Source File: widgets.py From ishare with MIT License | 5 votes |
def render(self, name, value, attrs=None, renderer=None): if value is None: value = '' # 传入模板的参数 editor_id = "id_%s" % name.replace("-", "_") uSettings = { "name": name, "id": editor_id, "value": value } if isinstance(self.command, list): cmdjs = "" if isinstance(self.command, list): for cmd in self.command: cmdjs = cmdjs + cmd.render(editor_id) else: cmdjs = self.command.render(editor_id) uSettings["commands"] = cmdjs uSettings["settings"] = self.ueditor_settings.copy() uSettings["settings"].update({ "serverUrl": "/ueditor/controller/?%s" % urlencode(self._upload_settings) }) # 生成事件侦听 if self.event_handler: uSettings["bindEvents"] = self.event_handler.render(editor_id) context = { 'UEditor': uSettings, 'STATIC_URL': settings.STATIC_URL, 'STATIC_ROOT': settings.STATIC_ROOT, 'MEDIA_URL': settings.MEDIA_URL, 'MEDIA_ROOT': settings.MEDIA_ROOT } return mark_safe(render_to_string('ueditor.html', context))
Example #25
Source File: wagtail_hooks.py From django-oscar-wagtail with MIT License | 5 votes |
def editor_js(): return format_html( """ <script src="{0}{1}"></script> <script>window.chooserUrls.productChooser = '{2}';</script> """, settings.STATIC_URL, 'oscar_wagtail/js/product-chooser.js', reverse('oscar_wagtail:product_choose') )
Example #26
Source File: models.py From elmer with MIT License | 5 votes |
def get_picture(self): """Returns profile picture url (if any).""" default_picture = settings.STATIC_URL + 'img/ditto.jpg' if self.dp: return self.dp.url else: return default_picture
Example #27
Source File: models.py From elmer with MIT License | 5 votes |
def get_picture(self): """Return cover url (if any) of a board.""" default_picture = settings.STATIC_URL + 'img/cover.png' if self.cover: return self.cover.url else: return default_picture
Example #28
Source File: wagtail_hooks.py From wagtail-cookiecutter-foundation with MIT License | 5 votes |
def editor_css(): # Add extra CSS files to the admin like font-awesome css_files = [ 'node_modules/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
Example #29
Source File: staticfiles.py From clist with Apache License 2.0 | 5 votes |
def static_ts(path): url = os.path.join(settings.STATIC_URL, path) if not settings.DEBUG: filepath = os.path.join(settings.STATIC_ROOT, path) timestamp = int(os.path.getmtime(filepath)) url = f'{url}?{timestamp}' return url
Example #30
Source File: middleware.py From pasportaservo with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) exclude_urls = [ reverse('admin:index'), url_index_debug, settings.STATIC_URL, settings.MEDIA_URL, '/favicon.ico', url_index_maps, ] self.exclude_urls = tuple(str(url) for url in exclude_urls)