小编san*_*pal的帖子

如何解决 __init__() 需要 1 个位置参数,但给出了 2 个

视图.py

from django.views.generic import ListView
from django.contrib.auth.models import User
class UserListView(ListView):
    model = User
    template_name = 'infinitescroll/articles.html' 
    context_object_name = 'users' 
    paginate_by = 10
    queryset = User.objects.all()  
Run Code Online (Sandbox Code Playgroud)

网址.py

from django.contrib import admin
from django.urls import path
from infinitescroll.views import UserListView

urlpatterns = [
    path('admin/', admin.site.urls),
    path('home/',UserListView, name='home'),
]
Run Code Online (Sandbox Code Playgroud)

文章.html

<table class="table table-bordered">
  <thead>
    <tr>
      <th>Username</th>
      <th>First name</th>
      <th>Email</th>
    </tr>
  </thead>
  <tbody>
    {% for user in users %}
      <tr>
        <td>{{ user.username }}</td>
        <td>{{ user.first_name }}</td>
        <td>{{ user.email }}</td>
      </tr>
    {% endfor %} …
Run Code Online (Sandbox Code Playgroud)

django django-views django-rest-framework

1
推荐指数
1
解决办法
374
查看次数