Django: Multiple URL parameters
<p>I'm making a study app that involves flashcards. It is divided into subjects. Each subject (biology, physics) has a set of decks (unitone, unittwo). Each deck has a set of cards (terms and definitions). I want my URLs to look like 
localhost:8000/biology/unitone/ but I have trouble putting two URL parameters in one URL.</p>

<p><strong>models.py</strong></p>

<pre><code>class Subject(models.Model):
    subject_name = models.CharField(max_length=100)
    description = models.TextField()

    def __str__(self):
        return self.subject_name

    def get_absolute_url(self):
        return reverse('card:index')

class Deck(models.Model):
    deck_name = models.CharField(max_length=100)
    subject = models.ForeignKey(Subject, on_delete=models.CASCADE)

    def __str__(self):
        return self.deck_name

class Card(models.Model):
    term = models.CharField(max_length=100)
    definition = models.TextField()
    deck = models.ForeignKey(Deck, on_delete=models.CASCADE)

    def __str__(self):
        return self.term
</code></pre>

<p><strong>views.py</strong></p>

<pre><code>class IndexView(generic.ListView):
   template_name = 'card/index.html'
   context_object_name = 'subjects'

   def get_queryset(self):
       return Subject.objects.all()

class SubjectView(DetailView):
    model = Subject
    slug_field = "subject"
    template_name = 'card/subject.html'

class DeckView(DetailView):
    model = Deck
    slug_field = "deck"
    template_name = 'card/deck.html'
</code></pre>

<p><strong>urls.py</strong></p>

<pre><code># localhost:8000/subjects/1 (biology)
url(r'^subjects/(?P&lt;pk&gt;[0-9]+)/$', views.SubjectView.as_view(), name='subject')


# localhost:8000/subjects/1/1 (biology/unitone)
url(r'^subjects/(?P&lt;pk&gt;[0-9]+)/(?P&lt;pk&gt;[0-9]+)/$', views.DeckView.as_view(), name='deck'),
</code></pre>

<p>The second URL in urls.py is what I'm having trouble with. It's not a valid URL.</p>

<p>You can't have multiple parameters with the same name. You have to give each parameter a unique name, e.g.:</p>

<pre><code>url(r'^subjects/(?P&lt;pk&gt;[0-9]+)/(?P&lt;deck&gt;[0-9]+)/$', views.DeckView.as_view(), name='deck'),
</code></pre>

<p>In the <code>DeckView</code> you can then access them as <code>self.kwargs['pk']</code> and <code>self.kwargs['deck']</code>. </p>

python django