[Fixed]-How to pass variable from view page to base template

1👍

The {{ request.user }} method is built in with Django, and you can use this in any template to access the User object.

If you want to display the user’s name in the navbar you can use:

{{ request.user.first_name|capfirst }} {{ request.user.last_name|capfirst }}

As can be seen this has the use of a template tag |capfirst to capitalise the first letter.

👤drew

0👍

according to doc, redirect will accept

  • A model: the model’s get_absolute_url() function will be called.

  • A view name, possibly with arguments: reverse() will be used to reverse-resolve the name.

  • An absolute or relative URL, which will be used as-is for the redirect location.

So redirect to specific view which render the base html. In html

{% if request.user.is_authenticated %}
    {{ request.user.username }}
{% endif %}

Leave a comment