context recognition in vs code with django

Hi all, django n00b here!

i was exoerimenting with django and various IDEs to see what best suits me.
so i was trying the following simple example:
inside views i defined a function for say home_page where i returned an html rendered template providing context like so:

def  home_page(request):
    context = {'variable1': 1}
    return render(request, 'homepage.html', context=context)

then inside the html page i tried something simple like this

{% if variable1 == 1 %}
    var = 1
{% else %}
    var != 1
{% endif %}

i understand that after using variable1 for the first time inside the template the ide will propose it every time i type var… but the first time will not know about it?

is there a way to make the template know that variable1 is actually available? is this doable at all? is it a matter of ide? plugin? configuration?

thx for any replies!

There probably isn’t because there’s no direct link between a template and the context.

Different factors apply:

  • A template can be rendered by multiple views, each providing a different context, with different variables.

  • Context processors exist to “inject” additional data into contexts.

  • Multiple rendering engines are possible such that render can mean different things.

My suggestion is to always keep in mind that a template is not the “active” component in Django - it’s just data being processed by a rendering engine, as is the context. It’s the rendering engine that is doing the work here.

oh right, i will keep that in mind.

Actually the first point makes perfect sense. about points 2-3 i will need to study some more i guess :slight_smile:

thx for the reply!