title: Django Show Subcategories by Category Id
body: <p>I have a problem (I think) with urls and views. So that, I have 3 categories, and each of them has 3 subcategories. I want to open subcategories when clicked on each category. </p>
  
  <p>urls.py:</p>
  
  <pre><code>urlpatterns = [
      path('', views.index),
      url(r'^category/(?P&lt;pk&gt;\d+)$', views.category, name='category'),
  ]
  </code></pre>
  
  <p>views.py:</p>
  
  <pre><code>def category(request):
      categories = Category.objects.all()
      subcategories = SubCategory.objects.all()
      return render(request, 'category.html', {'categories': categories, 'subcategories': subcategories}
  </code></pre>
  
  <p>base.html:</p>
  
  <pre><code>{% for category in categories%}
      &lt;a class="dropdown-item" href="{% url 'category' pk=category.pk %}"&gt;{{ category.name }}&lt;/a&gt;
  {% endfor %}
  </code></pre>
  
  <p>models.py</p>
  
  <pre><code>class Category(models.Model):
      name = models.CharField(max_length=100)
      description = models.TextField()
  
      def __str__(self):
          return self.name
  
  
  class SubCategory(models.Model):
      name = models.CharField(max_length=100)
      category = models.ForeignKey(Category, on_delete=models.CASCADE)
      image_url = models.CharField(default=0, max_length=2000)
      price = models.IntegerField(default=0)
  </code></pre>