how to import login required in django

def login_view(request):
    if request.method == 'GET':
        cache.set('next', request.GET.get('next', None))

    if request.method == 'POST':
        # do your checks here

        login(request, user)

        next_url = cache.get('next')
        if next_url:
            cache.delete('next')
            return HttpResponseRedirect(next_url)

    return render(request, 'account/login.html')

Here is what the above code is Doing:
1. When the user first visits the login page, we check if there’s a next parameter in the URL. If there is, we store it in the cache.
2. When the user submits the login form, we check if there’s a next parameter in the cache. If there is, we redirect the user to that page.
3. If there’s no next parameter in the cache, we redirect the user to the home page.