[Fixed]-Using Django Login Required Mixin


We should inherit the LoginRequiredMixin first. because python will consider the method dispatch from the first inherited class(in this case).

from django.contrib.auth.mixins import LoginRequiredMixin

class ArtWorkCreate(LoginRequiredMixin, CreateView):
    login_url = '/index/'
    redirect_field_name = 'index'
    model = ArtWork


Just Define a Login url on the settings.py file
(also remove the login url on the class)


LOGIN_URL = 'login'


login_url is URL that users who don’t pass the test/authentication will be redirected to.

redirect_field_name attribute should be set to URL the user should be redirected to after a successful login.


Leave a comment