title: How do I correctly pass multiple arguments (from the template/context) to a view in Django?
body: <p>I am relatively new to Django (v=2.1). I am stuck since few days searching for a solution to this problem which I think is fairly easy but, despite reading many posts here and elsewhere, did not manage to solve it yet.
  I have two models: Teacher and Assignment. Very simplified:</p>
  
  <pre><code>models.py    
  
  class Teacher(models.Model):
      name = models.CharField(max_length=200)
  
  class Assignment(models.Model):
      title = models.CharField(max_length=200)
      teacher = models.ForeignKey(Teacher, on_delete=models.SET_NULL, null=True)
  </code></pre>
  
  <p>I have a (working) site with a list of Assignments of teacher nr. x which I produced with a generic DetailView function and some of the code looks like this:</p>
  
  <pre><code>assignments_list.html
  
  {% for assignment in teacher.assignment_set.all %}
      ...
      &lt;a href="{% url 'assignment-detail' pk1=assignment.teacher.pk pk2=assignment.pk %}"&gt;{{assignment.title}}&lt;/a&gt;
      ...
  {% endfor %}
  </code></pre>
  
  <p>When I click on the assignment.title I want to get the detail page of the assignment of this specific teacher.
  I use this url conf:</p>
  
  <pre><code>urls.py
  
  urlpatterns += [path('teacher/&lt;int:pk1&gt;/assignment/&lt;int:pk2&gt;/', views.AssignmentDetailView.as_view(), name = 'assignment-detail')]
  </code></pre>
  
  <p>and I use this view function (I tried several variants):</p>
  
  <pre><code>views.py
  
  from .models import Teacher, Assignment
  from django.views import generic
  
  class AssignmentDetailView(generic.DetailView):
      model = Assignment
      template_name = 'assignment_detail.html'
  
      def get_queryset(self, **kwargs):
          queryset = super(AssignmentDetailView, self).get_queryset()
          return queryset.filter(teacher_id=self.kwargs['pk1'], pk=self.kwargs['pk2'])
  </code></pre>
  
  <p>I'm trying to pass the two parameters (pk1 and pk2) that are in the context of the page (that contains the list of assignments).
  If I click on the link (assignment.title) I do see a url with the correct numbers for pk1 and pk2 (I see that in the url address bar, e.g. <a href="http://localhost:8000/teacher/2/assignment/4" rel="nofollow noreferrer">http://localhost:8000/teacher/2/assignment/4</a>). But no page is displayed. By tweaking a bit things I get different errors:</p>
  
  <ul>
  <li>Syntax errors, problems with missing arguments... so far solved.</li>
  <li>'The queryset didn't retrieve any object' (or similar wording).</li>
  <li>Current error: 'The view app.views.AssignmentDetailView didn't return an HttpResponse object. It returned None instead.'</li>
  </ul>
  
  <p>My questions:</p>
  
  <ol>
  <li>What am I doing wrong? Am I passing correctly? Or is the problem in
  my view?... How to pass arguments (Teacher pk and Assignment pk)
  from the template (or, simply, the context?) to a view function? And
  how to use them to return the correct object(s) from my model(s)?</li>
  <li>Do I have to pass parameters every time a call a view function or are
  parameters passed automatically from one view(template) to another?</li>
  <li>Initially I will pass arguments through the URL but later I would like to pass them without going through the URL: can I still use the template
  arguments but use them only in the view (not in the url)? Is this
  the way to go?</li>
  </ol>
  
  <p>Thank you so much for any advice.</p>