Jinja2 and Django-unicorn #495
Unanswered
bschollnick
asked this question in
Q&A
Replies: 1 comment
-
Hmm, this is not something I've ever tried to do. :) To answer your question, I look forward to seeing if this is possible and what you come up with! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Folks,
I'm trying to get Django-unicorn to play nicely with Jinja2 templates (via Jinja2 and Django-Jinja.
This isn't so crazy as it sounds... But requires a couple of tags to be added to the Jinja2 environment.
e.g.
`
from django.templatetags.static import static
from django.urls import reverse
from django_icons.templatetags.icons import icon_tag
from jinja2 import Environment
from django_unicorn.templatetags.unicorn import unicorn_scripts, unicorn
def environment(**options):
env = Environment(**options)
env.globals.update({
'static': static,
'url': reverse,
'icon':icon_tag,
'unicorn':unicorn,
'unicorn_scripts':unicorn_scripts,
})
return env
`
when used in a jinja2 template, e.g.
`
{{ unicorn }}
<script src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.lazy/1.7.9/jquery.lazy.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.lazy/1.7.9/jquery.lazy.plugins.min.js"></script> <title>{% block title %} {{ gallery_name }} {% endblock %}</title> `I'm getting an error stating that it requires parameters.
Which makes sense due to the parameters in the function...
But according to the documentation, unicorn doesn't have any parameters?
{% load unicorn %}
{% unicorn_scripts %} {% csrf_token %} -----------So what am I missing here? Did I misunderstand something?
Beta Was this translation helpful? Give feedback.
All reactions