Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

LoginRequiredMixin not work Properly with login URL

$
0
0

I'm working on a Django project where I have implemented a ListView to display a list of checkout items (ListCheckoutView). I want to require authentication for accessing this view, but currently, it's accessible even without logging in. I've tried using the LoginRequiredMixin, but it doesn't seem to be working as expected. In the checkout.html works properly

from django.urls import pathfrom .views import BooksListView, BooksDetailView, BookCheckoutView, OrderComplete, SearchResultsListView, ListCheckoutViewurlpatterns = [    path('', BooksListView.as_view(), name='list'),    path('books/', ListCheckoutView.as_view(), name='list2'),    path('<int:pk>/', BooksDetailView.as_view(), name='detail'),    path('<int:pk>/checkout/', BookCheckoutView.as_view(), name='checkout'),    path('complete/', OrderComplete, name='complete'),    path('search/', SearchResultsListView.as_view(), name='search_results'),]
from django.views.generic import ListViewfrom django.contrib.auth.mixins import LoginRequiredMixin from .models import Book, Orderclass ListCheckoutView(LoginRequiredMixin, ListView):    model = Book    template_name = 'base.html'    login_url = 'login'
class BookCheckoutView(LoginRequiredMixin, DetailView):model = Booktemplate_name = 'checkout.html'login_url     = 'login'

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>