title: Django generate many pages with a single view
body: <p>my project consists of making a library with different categories of books. for each category of book I made as many views.
  I would like to know if for all the existing categories I can make a single view.</p>
  <hr />
  <p>For example here instead of three views I want only one view to manage all categories</p>
  <h2 id="views.py-ex6d">views.py</h2>
  <pre class="lang-py prettyprint-override"><code>def mathematics(request):
      mathematics_books = Books.objects.filter(category_id=1)
      total_mathematics_books = mathematics_books.count()
  
      page = request.GET.get('page', 1)
  
      paginator = Paginator(mathematics_books, 5)
      try:
          page_obj = paginator.page(page)
      except PageNotAnInteger:
          page_obj = paginator.page(1)
      except EmptyPage:
          page_obj = paginator.page(paginator.num_pages)
  
      context = {
          'total_mathematics_books': total_mathematics_books,
          'page_obj': page_obj,
      }
  
      return render(request, 'mathematics.html',context)
  
  
  def biology(request):
      biology_books = Books.objects.filter(category_id=2)
      total_biology_books = biology_books.count()
  
      page = request.GET.get('page', 1)
  
      paginator = Paginator(biology_books, 5)
      try:
          page_obj = paginator.page(page)
      except PageNotAnInteger:
          page_obj = paginator.page(1)
      except EmptyPage:
          page_obj = paginator.page(paginator.num_pages)
  
      context = {
          'total_biology_books': total_biology_books,
          'page_obj': page_obj,
      }
  
      return render(request, 'biology.html',context)
  
  def chemistry(request):
      chemistry_books = Books.objects.filter(category_id=3)
      total_chemistry_books = chemistry_books.count()
  
      page = request.GET.get('page', 1)
  
      paginator = Paginator(chemistry_books, 5)
      try:
          page_obj = paginator.page(page)
      except PageNotAnInteger:
          page_obj = paginator.page(1)
      except EmptyPage:
          page_obj = paginator.page(paginator.num_pages)
  
      context = {
          'total_chemistry_books': total_chemistry_books,
          'page_obj': page_obj,
      }
  
      return render(request, 'chemistry.html',context)
  </code></pre>
  <h2 id="models.py-8jf3">models.py</h2>
  <pre class="lang-py prettyprint-override"><code>class Categories(models.Model):
      name = models.CharField(max_length=250)
      description = models.TextField(blank=True)
  
      def __str__(self):
          return self.name
  
  
  class Authors(models.Model):
      name = models.CharField(max_length=250)
      biography = models.TextField(blank=True)
  
      def __str__(self):
          return self.name
  
  
  class Books(models.Model):
      author = models.ManyToManyField(Authors)
      title = models.CharField(max_length=250)
      description = models.TextField(blank=True)
      cover = models.ImageField(upload_to='pics/covers/', default='pics/default-cover.jpg')
      category = models.ForeignKey(Categories, on_delete=models.CASCADE)
  
      def __str__(self):
          return self.title
  </code></pre>
  <h2 id="urls.py-al84">urls.py</h2>
  <pre class="lang-py prettyprint-override"><code>urlpatterns = [
      path('', views.home, name='home'),
  
      path('book/&lt;int:id&gt;/', views.detailView, name='book_detail'),
      path('all_my_books/', views.allbooks, name='allbooks'),
  
      #Category
      path('mathematics/', views.mathematics, name='mathematics'),
      path('chemistry/', views.chemistry, name='chemistry'),
      path('biology/', views.biology, name='biology'),
  ]
  </code></pre>