PyCharm Django project with Jinja2 templates - no named URL tags or navigation

Hi,

 

We migrated our Django project to use Jinja2 templates, but now don't get Django specific autocompletion (it worked before on Django's own template language). For example (the big one) when we create named url tags the route name isn't suggested.

 

    {{ url('some_route')  }}

 

These are the 2 key features which are no longer working. Normal Jinja2 tags such as `{% extends ... %}` etc work ok, so PyCharm certainly knows the files are Jinja2. It seems to be just the Django specific stuff which isn't working.

- https://www.jetbrains.com/help/pycharm/completion-and-navigation-for-named-url-tags-in-django-templates.html#

- https://www.jetbrains.com/help/pycharm/part-6-framework-specific-navigation.html#

 

Does anyone have any suggestions? I've trawled through settings and set everything in the way in which I think should work. I'm using PyCharm Professional.

 

Thanks for your help.

2 comments
Comment actions Permalink

Hi,

I think it should work, since we support Jinja2 templates for Django.

Could you provide a project example that reproduces the issue?

0
Comment actions Permalink

I have the same issue — {{ url('path') }} autocompletion and Go To feature doesn't work in PyCharm when switched from Django templates to Jinja2.

If it could help I can create an empty Django/Jinja2 project, but it's nothing special, just basic settings from djangoproject.com docs.

I think the problem is that PyCharm treats {{ url() }} as basic Jinja2 function and not as Django's {% url %} template tag.

Here is part of configuration:

def environment(**options):
env = Environment(**options)

def url(viewname, *args, **kwargs):
"""
Return a URL to a view.
"""
return reverse(viewname, args=args, kwargs=kwargs)

env.globals.update({
'static': staticfiles_storage.url,
'url': url,
})
0

Please sign in to leave a comment.