{% else %}
<span><a href='/t/'>Training</a></span>
{% endif %}
+
+ {% if request.user.is_authenticated %}
+ <span>Logged in as <a href='{% url "user:self-profile-detail" %}'>{{ request.user.username }}</a>.</span>
+ {% endif %}
</nav>
{% block content %}{% endblock %}
from . import views
+app_name = 'user'
+
urlpatterns = (
+ path(
+ '',
+ views.user_profile_detail,
+ name='self-profile-detail',
+ ),
path(
'<str:username>',
views.user_profile_detail,
- name='user-profile-detail',
+ name='profile-detail',
),
)
from django.contrib.auth.models import User
+from django.http import Http404
from django.shortcuts import get_object_or_404
from django.views.generic.detail import DetailView
model = User
def get_object(self):
- return get_object_or_404(User, username=self.kwargs['username'])
+ username = self.kwargs.get('username')
+
+ if username:
+ return get_object_or_404(User, username=username)
+
+ if self.request.user.is_authenticated:
+ return self.request.user
+
+ raise Http404()
user_profile_detail = UserProfileDetailView.as_view()