Django4 + Jinja2 href url not working in template
I can't get simple urls to work in my Jinja2 templates in Django 4. This literally should be the easiest code, but it keeps throwing errors like this:
("Encountered unknown tag 'url'.",)
Request Method: GET
Request URL: http://127.0.0.1:8000/browse/a/
Django Version: 4.0
Exception Type: TemplateSyntaxError
Exception Value:
("Encountered unknown tag 'url'.",)
Exception Location: /home/joop/.local/share/virtualenvs/khinsider-gSzZqK6P/lib/python3.8/site-packages/django/template/backends/jinja2.py, line 47, in get_template
Python Executable: /home/joop/.local/share/virtualenvs/khinsider-gSzZqK6P/bin/python
Python Version: 3.8.10
Python Path:
['/home/joop/sites/khinsider',
'/snap/pycharm-community/261/plugins/python-ce/helpers/pydev',
'/home/joop/sites/khinsider',
'/snap/pycharm-community/261/plugins/python-ce/helpers/third_party/thriftpy',
'/snap/pycharm-community/261/plugins/python-ce/helpers/pydev',
'/home/joop/.cache/JetBrains/PyCharmCE2021.3/cythonExtensions',
'/usr/lib/python38.zip',
'/usr/lib/python3.8',
'/usr/lib/python3.8/lib-dynload',
'/home/joop/.local/share/virtualenvs/khinsider-gSzZqK6P/lib/python3.8/site-packages']
This is the template code: <a href="{% url 'browse' 'a' %}">test</a>
.
The urls.py path: path('browse/<str:char>/', main.views.browse, name='browse')
The settings TEMPLATES config:
TEMPLATES = [
{
"BACKEND": "django.template.backends.jinja2.Jinja2",
"DIRS": ['jinja2'],
"APP_DIRS": True,
},
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
I tried all kinda of variations but nothing works.
Edit: I found an answer that involves all kinds of custom environment settings, surely this shouldn't be this complicated?
Django & Jinja2 templates using {{ url() }}