为什么显示 View.as_view() 需要 1 个位置参数,但给出了 2 个
Why does it shows View.as_view() takes 1 positional argument but 2 were given
我不太确定哪里出了问题。我只是 Django 的初学者,我正在尝试创建一个简单的待办事项列表。
我想直接调用注销如果我点击注销它会进入登录。
urls.py
from fileinput import nextfile
from django.urls import path
from .views import TaskList, TaskDetails, TaskCreate, TaskUpdate, DeleteView, CustomLoginView
from django.contrib.auth.views import LogoutView
urlpatterns =[
path('login/',CustomLoginView.as_view,name='login'),
path('logout/', LogoutView.as_view(next_page='login'),name='logout'),
path('', TaskList.as_view(),name='task'),
path('task/<int:pk>/', TaskDetails.as_view(),name='task'),
path('task-create/', TaskCreate.as_view(),name='task-create'),
path('task-update/<int:pk>/', TaskUpdate.as_view(),name='task-update'),
path('task-delete/<int:pk>/', DeleteView.as_view(),name='task-delete'),
]
```
task_list.html
{% if request.user.is_authenticated %}
<p>{{request.user}}</p> <!--shows who is the current user with that task -->
<a href="{% url 'logout' %}">Log me out</a>
{% else %}
<a href="{% url 'login' %}">Ready to Login</a>
{% endif %}
<hr>
<h1>My To Do List</h1>
<a href="{% url 'task-create' %}"> Add Task</a>
<table>
<tr>
<th>Items</th>
<th></th>
</tr>
{% for task in tasks %}
<tr>
<td>{{task.title}}</td>
<td><a href="{% url 'task' task.id %}">View</a></td>
<td><a href="{% url 'task-update' task.id %}">Edit</a></td>
<td><a href="{% url 'task-delete' task.id %}">Delete</a></td>
</tr>
{% empty %}
<h3>No Items in List</h3>
{% endfor %}
</table>
您应该调用 .as_view(…)
方法,因此:
# call the method 🖟🖟
path('login/', CustomLoginView.as_view<strong>()</strong>, name='login'),
我不太确定哪里出了问题。我只是 Django 的初学者,我正在尝试创建一个简单的待办事项列表。 我想直接调用注销如果我点击注销它会进入登录。
urls.py
from fileinput import nextfile
from django.urls import path
from .views import TaskList, TaskDetails, TaskCreate, TaskUpdate, DeleteView, CustomLoginView
from django.contrib.auth.views import LogoutView
urlpatterns =[
path('login/',CustomLoginView.as_view,name='login'),
path('logout/', LogoutView.as_view(next_page='login'),name='logout'),
path('', TaskList.as_view(),name='task'),
path('task/<int:pk>/', TaskDetails.as_view(),name='task'),
path('task-create/', TaskCreate.as_view(),name='task-create'),
path('task-update/<int:pk>/', TaskUpdate.as_view(),name='task-update'),
path('task-delete/<int:pk>/', DeleteView.as_view(),name='task-delete'),
]
```
task_list.html
{% if request.user.is_authenticated %}
<p>{{request.user}}</p> <!--shows who is the current user with that task -->
<a href="{% url 'logout' %}">Log me out</a>
{% else %}
<a href="{% url 'login' %}">Ready to Login</a>
{% endif %}
<hr>
<h1>My To Do List</h1>
<a href="{% url 'task-create' %}"> Add Task</a>
<table>
<tr>
<th>Items</th>
<th></th>
</tr>
{% for task in tasks %}
<tr>
<td>{{task.title}}</td>
<td><a href="{% url 'task' task.id %}">View</a></td>
<td><a href="{% url 'task-update' task.id %}">Edit</a></td>
<td><a href="{% url 'task-delete' task.id %}">Delete</a></td>
</tr>
{% empty %}
<h3>No Items in List</h3>
{% endfor %}
</table>
您应该调用 .as_view(…)
方法,因此:
# call the method 🖟🖟
path('login/', CustomLoginView.as_view<strong>()</strong>, name='login'),