{% extends "base.html" %} {% block title %}Public Page – django-login-default{% endblock %} {% block content %}

Public Page

{% if user.is_authenticated %} You're logged in as {{ user.username }}, but this page doesn't require it. {% else %} You're not logged in — and this page works anyway. {% endif %}
How does this page opt out?

The view uses NoLoginRequiredMixin, which sets no_login_required = True on the class. The middleware sees that and lets the request through.

Class-based view:

from django_login_default.mixins import NoLoginRequiredMixin

class PublicView(NoLoginRequiredMixin, TemplateView):
    template_name = "public.html"

Function-based view:

from django_login_default.decorators import no_login_required

@no_login_required
def public_page(request):
    return render(request, "public.html")

Both approaches do the same thing — they set an attribute that the middleware checks before deciding whether to redirect.

{% if user.is_authenticated %}
{% csrf_token %}
{% endif %} Try the Dashboard (protected) →
{% endblock %}