(Django) 身份验证 + __init__ 参数问题

(Django) Authentication + __init__ argument issue

今天我有一个关于访问我的网页时遇到的 INIT 错误的问题。

我使用@login_required 装饰器来锁定未经身份验证的用户对我的日程安排日历的访问权限。虽然身份验证工作正常,但由于此问题末尾的错误,我无法查看我的网站。

VIEWS.PY

@login_required(login_url='login')
class CalendarView(generic.ListView):
    model = Event
    template_name = 'cal/calendarpage.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        d = get_date(self.request.GET.get('month', None))
        cal = Calendar(d.year, d.month)
        html_cal = cal.formatmonth(withyear=True)
        context['calendar'] = mark_safe(html_cal)
        context['prev_month'] = prev_month(d)
        context['next_month'] = next_month(d)
        return context

URLS.PY

urlpatterns = [
    path('calendarpage/', views.CalendarView, name='calendarpage'),
    re_path('event/new/$', views.event, name='event_new'),
        re_path('event/edit/(?P<event_id>\d+)/$', views.event, name='event_edit'),
]

如果我将 .as_view() 添加到我的 url 并删除身份验证,则访问网页没有问题,但没有不需要的身份验证。

TypeError at /calendarpage/

__init__() takes 1 positional argument but 2 were given

Request Method:     GET
Request URL:    http://localhost:8000/calendarpage/
Django Version:     3.1.2
Exception Type:     TypeError
Exception Value:    

__init__() takes 1 positional argument but 2 were given

Exception Location:     C:\Users\*USER*\Desktop\Python\VENV\lib\site-packages\django\contrib\auth\decorators.py, line 21, in _wrapped_view
Python Executable:  C:\Users\*USER*\Desktop\Python\VENV\Scripts\python.exe
Python Version:     3.8.6
Python Path:    

['C:\Users\*USER*\Desktop\Python\*PROJECT*',
 'C:\Program '
 'Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\python38.zip',
 'C:\Program '
 'Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\DLLs',
 'C:\Program '
 'Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib',
 'C:\Users\*USER*\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0',
 'C:\Users\*USER*\Desktop\Python\VENV',
 'C:\Users\*USER*\Desktop\Python\VENV\lib\site-packages']

Server time:    Tue, 08 Dec 2020 15:08:43 +0100

你们能找出导致我出错的问题吗?正如我所见,这是通往全球 Django 装饰器的路径,但没有“init”之类的东西 我在下面的 utils 文件中唯一的 init

UTILS.PY - 整个文件

class Calendar(HTMLCalendar):
    def __init__(self, year=None, month=None):
        self.year = year
        self.month = month
        super(Calendar, self).__init__()

    # formats a day as a td
    # filter events by day
    def formatday(self, day, events):
        events_per_day = events.filter(start_time__day=day)
        d = ''
        for event in events_per_day:
            d += f'<li> {event.get_html_url} </li>'

        if day != 0:
            return f"<td><span class='date'>{day}</span><ul> {d} </ul></td>"
        return '<td></td>'

    # formats a week as a tr
    def formatweek(self, theweek, events):
        week = ''
        for d, weekday in theweek:
            week += self.formatday(d, events)
        return f'<tr> {week} </tr>'

    # formats a month as a table
    # filter events by year and month
    def formatmonth(self, withyear=True):
        events = Event.objects.filter(start_time__year=self.year, start_time__month=self.month)

        cal = f'<table border="0" cellpadding="0" cellspacing="0" class="calendar">\n'
        cal += f'{self.formatmonthname(self.year, self.month, withyear=withyear)}\n'
        cal += f'{self.formatweekheader()}\n'
        for week in self.monthdays2calendar(self.year, self.month):
            cal += f'{self.formatweek(week, events)}\n'
        return cal

关闭这个问题,因为我发现我使用了循环命令 X 身份验证试图对自己进行身份验证,现在已更正 >.<