Доброго времени суток!
Продолжаю осваивать Django, однако ж хотелось бы спросить у профессионалов в верном ли направлении мыслю.
Задача: выводить на странице /sample/ в зависимости от статуса аутентификации один из двух блоков.
В шаблоне sample.html:
{% if request.user.is_authenticated %}
Блок 0
{% else %}
Блок 1
{% endif %}
В представлении views.py:
class PostListView(ListView):
"""
Представление в виде списка
"""
model = Post
def get(self, request, *args, **kwargs):
self.request = request
return super(PostListView, self).get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super(PostListView, self).get_context_data(**kwargs)
context['request'] = self.request
return context
То бишь таким вот образом передаю request для дальнейшей обработки в шаблоне.
Вопрос: не изобретаю ли Я велосипед, может, есть более простой способ?
Использовалась следующая дока: https://docs.djangoproject.com/en/1.7/ref/class-based-views/generic-display/
Спасибо за понимание.