-
Notifications
You must be signed in to change notification settings - Fork 681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use local bootstrap? #350
Comments
You can override the |
@ikcam I think @cl0ne tries to ask how to get an url to the location of a static file in the You might succeed in doing it automatically, but you'll need some lazy approach: generating the url will require some settings to be defined so it cannot be returned as a string from a function ran in settings.py if that makes sense... |
@ikcam It's not possible to use
|
@jieter You're right. Probably some wrapper with |
Thanks @jieter for idea! Came up with the following approach: from django.templatetags.static import static
class StaticWrapper:
def __init__(self, path):
self.path = path
def __str__(self):
return static(self.path)
BOOTSTRAP3 = {
'css_url': StaticWrapper('bootstrap/dist/css/bootstrap.min.css'),
'jquery_url': StaticWrapper('jquery/dist/jquery.min.js'),
'javascript_url': StaticWrapper('bootstrap/dist/js/bootstrap.min.js'),
} |
Good solution @jieter. But this could use a better fix, I'll look at examples form Django static urls to see if we could just apply |
@gaelanadams I define it in separate file and then import in |
May be simply:
|
The most elegant solution would be if I ran the resulting url through static.
|
I don't see the upside to loading a template tag for this. So for example I'm using: STATIC_URL = '/static/'
# ...
BOOTSTRAP3 = {
'jquery_url': STATIC_URL + 'js/jquery.min.js',
'css_url': STATIC_URL + 'css/bootstrap.min.css',
'theme_url': STATIC_URL + 'css/bootstrap-theme.min.css',
} This is analog to using |
The original reason for a template tag was to make it easy to use the same settings (JS, CSS, theme) in different templates. I agree that it's not a super big advantage, but it makes getting started easier. |
It's a documentation issue. People perceive the static template tag as magical, yet all it does is put STATIC_URL before the argument. BOOTSTRAP3 = {
'css_url': StaticWrapper('bootstrap/dist/css/bootstrap.min.css'),
'jquery_url': StaticWrapper('jquery/dist/jquery.min.js'),
'javascript_url': StaticWrapper('bootstrap/dist/js/bootstrap.min.js'),
} and this: BOOTSTRAP3 = {
'jquery_url': STATIC_URL + 'js/jquery.min.js',
'css_url': STATIC_URL + 'css/bootstrap.min.css',
'javascript_url': STATIC_URL + 'js/bootstrap.min.js',
} is no different to the end user, except that the first creates a circular dependency in the boot cycle of Django and loads a bunch of code. Solve this in the documentation, not the code. Now, if you want to make things easy on end users, then support something like: BOOTSTRAP3 = {
'css_url': 'css/bootstrap.min.css',
# ....
'urls_static': True,
} This avoids the circular dependency as you'd only have to transform them once one of the template tags is called and can simply defer to the static tag. |
|
Of course, I can override
css_url
with hardcoded URL. But how to usestatic
tag to get css file url without overriding wholebootstrap3.html
template?The text was updated successfully, but these errors were encountered: