1
votes

views.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()  

urls.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'),
]

articles.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 %}
  </tbody>
</table>

I don't know what causes an error it gives error locations in Exception

Location: C:\xampp\htdocs\8moviesdb\infinite\pal\lib\site-packages\django\core\handlers\base.py in _get_response, line 113

1
share full traceback of the error!Usman Maqbool

1 Answers

6
votes

In urls.py, instead of just UserListView, use UserListView.as_view(). It's how Django's class based views work.