-
Notifications
You must be signed in to change notification settings - Fork 73
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
Unable to use tags from django_vite with Jinja2 #8
Comments
Hi, |
Hi @mbacalan, django-jinja automatically loads django's built-in tags, but it has to be configured to load any third-party tags in your settings, like this: # settings.py
TEMPLATES = [
{
"BACKEND": "django_jinja.backend.Jinja2",
"OPTIONS": {
"globals": {
"vite_hmr_client": "django_vite.templatetags.django_vite.vite_hmr_client",
"vite_asset": "django_vite.templatetags.django_vite.vite_asset",
},
... Furthermore, in jinja templates, you call the tags as if they were functions, with {% load django_vite %}
<html>
<head>
<title>vite on django</title>
{% vite_hmr_client %}
</head>
<body>
<div id="app"></div>
{% vite_asset 'src/main.js' %}
</body>
</html> ...you would need to convert it to this in a jinja template: <html>
<head>
<title>vite on jinja</title>
{{ vite_hmr_client() }}
</head>
<body>
<div id="app"></div>
{{ vite_asset('src/main.js') }}
</body>
</html> I hope that helps. |
@wizpig64 thanks! Works like a charm. Maybe this issue can be closed, unless this is only applicable to |
This was very helpful. I think adding it to the readme would be a good idea 🙂 |
Hello,
I followed everything in the readme and took a look at the example app too but I can't seem to get it working on our company project. Every tag registered by django_vite, such as
load
,vite_hmr_client
etc. causes anEncountered unknown tag
error. I can see thedjango_vite
folder insidevenv
and it is present inINSTALLED_APPS
. The server starts with no errors so it doesn't look like there's an issue with installing the pip package but when I load the page, it flips out.We are using Jinja template engine via
django-jinja
package. I'm suspecting that's the cause?Let me know if you need more information about the project.
Thanks.
The text was updated successfully, but these errors were encountered: