[Fixed]-Django custom middleware

1👍

You can just do the same thing as the standard auth middleware; add the user object to the request.

def process_request(self, requess):
    username = <...get from token...>
    request.username = username

Now you can access it from the template via {{ request.username }} (assuming you’ve enabled the request context processor).

Leave a comment