88👍
✅
You need use as_view() at the end of class based views when declaring in the urls:
path('', views.HomeView.as_view(), name='homepage'),
Also, when using login_required
decorator, you need to use it on dispatch method of CBV:
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
class HomeView(ListView):
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(HomeView, self).dispatch(*args, **kwargs)
6👍
You need to use as_view()
at the end of class-based views when declaring in the URLs. Like this:
path('', views.HomeView.as_view(), name='homepage'),
- [Django]-Django Admin – Overriding the widget of a custom form field
- [Django]-Save() prohibited to prevent data loss due to unsaved related object
- [Django]-"You called this URL via POST, but the URL doesn't end in a slash" error in Django
0👍
In `urls.py replace by this path-code:
path(' ', views.HomeView.as_view(), name='homepage'),
from django.urls import path
from . import views
urlpatterns = [
path(' ', views.HomeView.as_view(), name='homepage'),
]
- [Django]-Django – How to get admin url from model instance
- [Django]-Proper way to consume data from RESTFUL API in django
- [Django]-Get the file path for a static file in django code
Source:stackexchange.com