I'd like BracketHighlighter to highlight my django template brackets {% %} and {{ }}.
I've made the following edits to User/bh_core.sublime-settings:
"user_brackets": [
{
"name": "django",
"open": "(\\{\\%)",
"close": "(\\%\\})",
"style": "django",
"scope_exclude": ["string", "comment"],
"scope_exclude_exceptions": ["text.tex string.other.math"],
"language_filter": "blacklist",
"language_list": ["Plain text", "Hex"],
"find_in_sub_search": "true",
"ignore_string_escape": true,
"enabled": true
}
]
but it doesn't seem to work (even after restarting ST2). I've tried using "user_scope_brackets" as well, with no luck. Anyone know of a solution?
Install a package which supports the Django template editing through the package manager.
Check the link below for understanding how to install and proceed with package manager
https://packagecontrol.io/
Related
I'm using django built-in templates tags which are {% load static %} {% extends 'base.html' %} etc. so whenever I'm saving my document by pressing ctrl+s the formatting which should be gets disturbed which causes errors:
Unclosed tag on line 1: 'block'. Looking for one of: endblock.
before saving the document the editor looks something like this:
but as soon as I save my document it becomes like this which results in the above mentioned error
any solution for that? maybe add or remove some formatting extensions?
Okay so I tweaked around some settings.json in vscode and found my solution:
add the following lines
"[django-html]": {
"editor.quickSuggestions": {
"other": true,
"comments": true,
"strings": true
},
"editor.defaultFormatter": "batisteo.vscode-django"
},
My assumption to this solution is that, earlier this [django-html] settings was not instantiated so by default a django-html template was getting formatted through [html] settings as seen in the image below (pls correct me if my assumption is wrong).
I try to replace default logo and title in a Wagtail app. According to http://docs.wagtail.io/en/v1.0b1/howto/custom_branding.html I've created templates/wagtailadmin/, have installed django-overextends and added overextends to my project’s INSTALLED_APPS object(base.py).
As a result is error Invalid block tag on line 1: 'overextends'. Did you forget to register or load this tag?
How can I correctly load overextends module to make it work? Any help appreciated. Thanks in advance.
See the overextends readme
In Django 1.9+, you must add overextends to the builtins key of your TEMPLATES setting
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
'OPTIONS': {
'builtins': ['overextends.templatetags.overextends_tags'],
}
},
]
For most extensions which feature template tags, you need to load them in each template, e.g. {% load overextends_tags %}, but overextends is different, and in earlier versions of Django it self-adds to the builtins, see https://github.com/stephenmcd/django-overextends/blob/master/overextends/models.py
Note, Wagtail 1.0 is an old version, and the latest is 1.5.2. The Wagtail 1.5.2 Custom Branding documentation does detail the above template configuration step.
Update October 2016: Wagtail is now well past version 1.5. See #gasman's comment below for more.
I am now using django ckeditor as a WYSIWYG editor for adding product information,
previously I was using Summernote, but after moving to production the widget would not display in my template (at all, just a big white space) so I decided to try ckeditor.
However with django CKEditor all I see is a normal textarea, rather than the WYSIWYG editor.
The source code from the template is as follows:
<div class="col-sm-2"> Description:</div><div class="col-sm-10"><div class="django-ckeditor-widget" data-field-id="id_description" style="display: inline-block;">
<textarea cols="40" id="id_description" name="description" rows="10" data-processed="0" data-config='{"toolbar_Basic": [["Source", "-", "Bold", "Italic"]], "language": "en-us", "height": 291, "width": 835, "toolbar": "Full", "skin": "moono", "toolbar_Full": [["Styles", "Format", "Bold", "Italic", "Underline", "Strike", "SpellChecker", "Undo", "Redo"], ["Link", "Unlink", "Anchor"], ["Image", "Flash", "Table", "HorizontalRule"], ["TextColor", "BGColor"], ["Smiley", "SpecialChar"], ["Source"]], "filebrowserWindowWidth": 940, "filebrowserWindowHeight": 725}' data-external-plugin-resources='[]' data-id="id_description" data-type="ckeditortype"></textarea>
My installation process was very simple: install django-ckeditor, (jquery already), add to installed apps, collectstatic, change the widget in my modelform, refresh server.
I am sure there is a simple thing I am missing here but I have no idea what it could be!
Any ideas?
You didn't mention if this is in admin or custom view.
If this is in a custom view check that both the widget .js file and jQuery are linked correctly in your page.
If it's in admin you probably don't have jQuery linked there and should add this to your settings.py:
CKEDITOR_JQUERY_URL = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
If both do not help share what errors your JS console gives you
I'm trying to get Jinja2 (and Django, via django-jinja) to localize a number, eg. 123456 becomes 123,456 (or, of course, 123.456 depending on the locale). I've read every bit of documentation I can find on the subject, and can't find anything that actually works. Using standard DTL, one could just do:
{% localize on %}{{ some_number }}{% endlocalize %}
This works fine in my project using regular Django templates, but of course, doesn't work in Jinja2. I mention that this works fine because anything involving settings.py such as USE_L10N being False can be ruled out.
I've tried the following, all based on documentation I've found:
{{ gettext("%(num)d", num=some_number) }} - outputs number with no commas or localization.
{% trans num=some_number %}{{ num }} {% endtrans %} - as suggested by the django-jinja documentation - outputs number with no commas or localization.
{{ _(some_number|string) }} - outputs number with no commas or localization.
{{ some_number|localize }} - localize is not a valid filter.
So, how can I easily and properly localize a number using Jinja2?
Figured it out. Jinja2 doesn't seem to handle localization on its own, but django-jinja includes a built-in contrib that wraps django.contrib.humanize.templatetags. According to the documentation for that, format localization is respected using the |intcomma filter if L10n is enabled.
To use it, add django_jinja.contrib._humanize to INSTALLED_APPS in settings.py:
INSTALLED_APPS += ('django_jinja.contrib._humanize',)
And then in templates, simply use the |intcomma filter:
{{ some_number|intcomma }}
Though it is an old question, I encountered the same found this solution feasible without lot of edits.
Here is library that implements L10n for jinja2 templates. You could integrate it with your application like
TEMPLATES = [
{
'BACKEND': 'django.template.backends.jinja2.Jinja2',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'extensions': [
'jdj_tags.extensions.DjangoStatic',
'jdj_tags.extensions.DjangoI18n',
'jdj_tags.extensions.DjangoL10n',
]
},
},
}
I would like to add a href link in my kibana dashboard. To do that, I add a "text" panel, select "html" mode, and edit the content with :
<a ng-href=intro.txt>Introduction</a>
When I add it and go to my dashboard, the introduction link appears but it has no href link, so clicking on it is possible but it does nothing.
When I inspect the element with chrome inspector, the tag looks like this:
<a>Introduction</a>
My json dashboard looks like this :
"panels": [
{
"error": false,
"span": 12,
"editable": true,
"type": "text",
"loadingEditor": false,
"mode": "html",
"content": "<a ng-href=intro.txt>Introduction</a> ",
"style": {
"font-size": "20pt"
},
"title": "WELCOME"
}
]
I hope someone know how to add an href link in kibana text panel.
Ok I found the solution, the href value must be conform to a particular regex, ie starts with https or ftp or mail. This is to prevent any script injection.