Providing 'default' User when not logged in instead of AnonymousUser
<p><strong>Is there a way to globally provide a custom instance of <code>User</code> class instead of <code>AnonymousUser</code>?</strong></p>

<p>It is not possible to assign <code>AnonymousUser</code> instances when <code>User</code> is expected (for example in forms, there is need to check for authentication and so on), and therefore having an ordinary <code>User</code> class with name 'anonymous' (so that we could search for it in the DB) would be globally returned when a non-authenticated user visits the page. Somehow implementing a custom authentication mechanism would do the trick? And I also want to ask if such an idea is a standard approach before diving into this.</p>

<p>You could create a custom middleware (called after AuthenticationMiddleware), that checks if the user if logged in or not, and if not, replaces the current user object attached to request, with the the user of your choice.</p>

python django