title: Pagination did not work on the first page. The current path, &vacancy=2, didn't match any of these
body: <p>I am implementing search with pagination in Django.
  When I clicked Next pagination button, received error:</p>
  
  <blockquote>
    <p>Page not found (404)
    Request Method: GET
    Request URL:    <a href="http://127.0.0.1:8001/&amp;vacancy%3D2" rel="nofollow noreferrer">http://127.0.0.1:8001/&amp;vacancy%3D2</a></p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/znQeO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/znQeO.png" alt="enter image description here"></a></p>
  
  <p>Also, pagination works after search (e.g. I searched something, then clicked pagination and it works)</p>
  
  <p>I think that problem with views.py an urls.py
  How can I solve the problem?</p>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>class Company(models.Model):
      name = models.CharField(max_length=200)
      about = models.TextField()
  
      def __str__(self):
          return self.name
  
  
  class Vacancy(models.Model):
      company_key = models.ForeignKey(Company, on_delete=models.CASCADE)
      title = models.CharField(max_length=200)
      salary = models.CharField(max_length=200, default='40.000')
      text = models.TextField(default="The text about vacancy")
      city = models.CharField(max_length=200, default='Москва')
      date_str = models.CharField(max_length=50, default='12 сентября')
  
      created_date = models.DateTimeField(default=timezone.now)
      published_date = models.DateTimeField(blank=True, null=True)
  
      CHOICES = [
          ('ALL', 'ALL'),
          ('IT', 'IT'),
          ('FINANCE', 'FINANCE'),
          ('OTHER', 'OTHER'),
      ]
      department = models.CharField(
          max_length=20,
          choices=CHOICES,
          default='ALL',
      )
  
      def publish(self):
          self.published_date = timezone.now()
          self.save()
  
      def __str__(self):
          return self.title
  </code></pre>
  
  <p><strong>urls.py</strong></p>
  
  <pre><code>urlpatterns = [
      path('', HomePageView.as_view(), name='vacancy_list'),
      path('search/', SearchResultsView.as_view(), name='search_results'),
      path('vacancy/&lt;int:pk&gt;/', views.vacancy_detail, name='vacancy_detail'),
  
      path('accounts/login/', BBLoginView.as_view(), name='login'),
      path('accounts/profile/', profile, name='profile'),
      path('accounts/logout/', BBLogoutView.as_view(), name='logout'),
      ...
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>class HomePageView(ListView):
      model = Vacancy
      template_name = 'vacancy_list/vacancy_list.html'
      paginate_by = 5
      page_kwarg = 'vacancy'
      context_object_name = 'vacancies'
  
  
  def vacancy_detail(request, pk):
      vacancy = get_object_or_404(Vacancy, pk=pk)
      return render(request, 'vacancy_list/vacancy_detail.html', {'vacancy': vacancy})
  
  
  class SearchResultsView(ListView):
      model = Vacancy
      template_name = 'vacancy_list/search_results.html'
      paginate_by = 5
      page_kwarg = 'vacancy'
      context_object_name = 'vacancies'
  
      def get_context_data(self, **kwargs):
          context = super().get_context_data(**kwargs)
          context['query'] = self.request.GET.get('q')
          # added param
          context['query2'] = self.request.GET.get('q2')
          return context
  
      def get_queryset(self): # new
          query = self.request.GET.get('q')
          query2 = self.request.GET.get('q2')
          object_list = Vacancy.objects.filter(
               Q(title__icontains=query) and Q(department__icontains=query2)
          )
          return object_list
  </code></pre>
  
  <p><strong>vacancy_list.html</strong></p>
  
  <pre><code>{% block content %}
  
  &lt;div class="container col-md-8" style="margin:20px;"&gt;
      &lt;div class="container" style="margin-top: 40px; font-size: 2rem; padding-left: 0px;"&gt;
          &lt;form action="{% url 'search_results' %}" method="get"&gt;
              &lt;div class="row"&gt;
                   &lt;div class="col-lg-8 col-md-6 col-xs-12"&gt;
                       &lt;input name="q" type="text" placeholder="Search..." class="form-control"&gt;
                   &lt;/div&gt;
                   &lt;div class="col-lg-3 col-md-4 col-xs-12"&gt;
                      &lt;select name="q2" class="form-control" id="exampleFormControlSelect1"&gt;
                          &lt;option&gt;ALL&lt;/option&gt;
                          &lt;option&gt;IT&lt;/option&gt;
                          &lt;option&gt;Finance&lt;/option&gt;
                          &lt;option&gt;Other&lt;/option&gt;
                      &lt;/select&gt;
                   &lt;/div&gt;
                   &lt;div class="col-lg-1 col-md-2 col-xs-12" style="padding-left: 0px;"&gt;
  
                       &lt;button  class="btn btn-primary"&gt;Primary&lt;/button&gt;
                   &lt;/div&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  
  
      {% for vacancy in vacancies %}
      &lt;div class="card"&gt;
          &lt;div class="card-header"&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-md-8"&gt;
                      &lt;h1&gt;&lt;a href="{% url 'vacancy_detail' pk=vacancy.pk %}"&gt;{{vacancy.title}}&lt;/a&gt;&lt;/h1&gt;
                  &lt;/div&gt;
                  &lt;div class="col-md-4 text-right"&gt;
                      &lt;p&gt; {{ vacancy.salary}} &lt;/p&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="card-body" style="white-space:normal"&gt;
              &lt;p class="text-secondary"&gt;{{vacancy.company_key.name}}&lt;/p&gt;
              &lt;p&gt; Описание вакансии: Компания Sixhands, занимающаяся разработкой мобильных приложений и веб-порталов в Санкт-Петербурге, ищет Backend-разработчика для создания серверной части мобильных приложений.
              &lt;div class="row"&gt;
                  &lt;div class="col-md-8"&gt;
                      &lt;p&gt;{{vacancy.city}} &lt;/p&gt;
                  &lt;/div&gt;
                  &lt;div class="col-md-4 text-right"&gt;
                      &lt;p&gt; {{vacancy.date_str }} &lt;/p&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
          &lt;/div&gt;
  
  
  
      &lt;/div&gt;
      {% endfor %}
  
  
      &lt;!-- Paginator --&gt;
      &lt;div class="container" style="font-size: 2rem;"&gt;
      &lt;div class="row justify-content-center"&gt;
      &lt;ul class="pagination"&gt;
          {% if page_obj.has_previous %}
              &lt;li class="page-item"&gt;&lt;a class="page-link" href="{{ request.get_full_path }}?vacancy={{ page_obj.previous_page_number }}"&gt;Previous&lt;/a&gt;&lt;/li&gt;
          {% else %}
              &lt;li class="page-item disabled"&gt;
                  &lt;span class="page-link"&gt;Previous&lt;/span&gt;
              &lt;/li&gt;
          {% endif %}
          &lt;li class="page-item disabled"&gt;
                  &lt;span class="page-link"&gt;Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}&lt;/span&gt;
          &lt;/li&gt;
          {% if page_obj.has_next %}
             &lt;li class="page-item"&gt;&lt;a class="page-link" href="{{ request.get_full_path }}?vacancy={{ page_obj.next_page_number }}"&gt;Next&lt;/a&gt;&lt;/li&gt;
          {% else %}
             &lt;li class="page-item disabled"&gt;
                &lt;span class="page-link"&gt;Next&lt;/span&gt;
             &lt;/li&gt;
          {% endif %}
  
      &lt;/ul&gt;
      &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt; &lt;!-- wrapper end --&gt;
  
  {% endblock %}
  </code></pre>