0
I am using Django authentication and in HTML templates works very well when I use for example:
{% if user.is_anonymous %}
...
{% else %}
...
{% endif %}
I would like to use this same "user", which refers to the logged in user, to select when loading a view.
Like I’m trying to do:
class IndexView(TemplateView):
template_name = 'index.html'
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
context['tabelas'] = Tabela.objects.filter(**usuario=user.id**)
return context
I would like to get id of the logged-in user who has a Foreignkey with Table and thus select only the data that matter. But error occurs:
NameError at /
name 'user' is not defined
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 3.2.4
Exception Type: NameError
Exception Value:
name 'user' is not defined
Does anyone know how I use the logged-in user in this snippet ?