8
6

More than 5 years have passed since last update.

Django2 ログイン中のユーザ名を表示する

Posted at

Djangoでwebアプリを開発するときに、ログインしているユーザー名を表示したい時があると思います。

今回は、そのログインユーザー名を表示するコードをご紹介します。

任意のファイル.html
{% if user.is_authenticated %}
<p>{{ user.get_username }}でログイン中</p>
{% else %}
<p>ログインしていません</p>
{% endif %}

たったこれだけです。
これをHTMLファイルに追加してください。

簡単ですね。

8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6