title: How to get product id and display its details in django
body: <p>I followed a YouTube tutorial to make e-commerce site and now I'm trying to learn by adding new features to it. I am able to populate different products from the model.</p>
  <p>I want to display the details of the clicked product on a different page.
  this is what i have done so far.</p>
  <p>Thanks</p>
  <p>models.py</p>
  <pre><code>class Product(models.Model):
  name=models.CharField(max_length=200,null=True)
  price=models.DecimalField(max_digits=7,decimal_places=2)
  digital=models.BooleanField(default=False,null=False,blank=False)
  image = models.ImageField(null=True,blank=True)
  description=models.CharField(max_length=500,null=True)
  
  def __str__(self):
      return self.name
  </code></pre>
  <p>views.py</p>
  <pre><code>def store(request):
      data=cartData(request)
      cartItems=data['cartItems']
      order=data['order']
      items=data['items']   
      products=Product.objects.all()
      context={'products':products,'cartItems':cartItems}
      return render(request,&quot;foodapp/home.html&quot;,context)
  
  def detail(request):
      products=Product.objects.get(id=product.id)
      context={'products':products}
  
      return render(request,&quot;foodapp/detail.html&quot;,context)
  </code></pre>
  <p>urls.py</p>
  <pre><code>urlpatterns=[
  path('',views.store,name='store'),
  path('cart/',views.cart,name='cart'),
  path('checkout/',views.checkout,name='checkout'),
  path('update_item/',views.updateItem,name='update_item'),
  path('signup/',views.SignUp.as_view(),name='signup'),
  path('logout/',auth_views.LogoutView.as_view(next_page='login'),name='logout'),
  path('login/',auth_views.LoginView.as_view(template_name='foodapp/login.html'),
                                                                  name='login'),
  path('process_order/',views.processOrder,name='process_order'),
  path('detail/',views.detail,name='detail'),                                                          
  </code></pre>
  <p>home.html</p>
  <pre><code>    {% for product in products %}   
      &lt;div style=&quot;margin-top: 30px;&quot; class=&quot;col-md-4&quot;&gt;
      &lt;div class=&quot;box-element product&quot;&gt;
      &lt;img  class=&quot;thumbnail&quot; src=&quot;{{product.imageURL}}&quot; alt=&quot;&quot;&gt;
      &lt;hr&gt;
      &lt;h6&gt;&lt;strong&gt;{{product.name}}&lt;/strong&gt;&lt;/h6&gt;
      &lt;hr&gt;
      &lt;h6&gt;Type:&lt;/h6&gt;
      &lt;button  data-product=&quot;{{ product.id }}&quot; data-action=&quot;add&quot; class=&quot;btn btn-outline-secondary add- 
       btn update-cart&quot;&gt;
      &lt;a href=&quot;#&quot;&gt; Add to Cart&lt;/a&gt;&lt;/button&gt;&amp;nbsp;
  
      &lt;button data-product=&quot;{{ product.id }}&quot;  class=&quot;btn btn-outline-secondary&quot;&gt;
          &lt;a href=&quot;{% url 'detail' %}&quot;&gt;View&lt;/a&gt;
  
      &lt;/button&gt;
      
      &lt;h4 style=&quot;display: inline-block; float: right;&quot;&gt;{{product.price}}
      &lt;/h4&gt;
      
      &lt;/div&gt; 
          
     &lt;/div&gt;
  </code></pre>
  <p>details.html</p>
  <pre><code>    {% for product in products %}   
      &lt;div style=&quot;margin-top: 30px;&quot; class=&quot;col-md-4&quot;&gt;
      &lt;div class=&quot;box-element product&quot;&gt;
      &lt;img  class=&quot;thumbnail&quot; src=&quot;{{product.imageURL}}&quot; alt=&quot;&quot;&gt;
      &lt;hr&gt;
      &lt;h6&gt;&lt;strong&gt;{{product.name}}&lt;/strong&gt;&lt;/h6&gt;
      &lt;hr&gt;
      &lt;h6&gt;Type:&lt;/h6&gt;
      &lt;button  data-product=&quot;{{ product.id }}&quot; data-action=&quot;add&quot; class=&quot;btn btn-outline-secondary add- 
       btn update-cart&quot;&gt;
      &lt;a href=&quot;#&quot;&gt; Add to Cart&lt;/a&gt;&lt;/button&gt;&amp;nbsp;
  
      &lt;button data-product=&quot;{{ product.id }}&quot; class=&quot;btn btn-outline-secondary&quot;&gt;
          &lt;a href=&quot;{% url 'detail' %}&quot;&gt;View&lt;/a&gt;
  
      &lt;/button&gt;
      
      &lt;h4 style=&quot;display: inline-block; float: right;&quot;&gt;{{product.price}}
      &lt;/h4&gt;
      
      &lt;/div&gt; 
          
      
          
      
       
    
  
  &lt;/div&gt;
  {% endfor %}
  </code></pre>
  <p>utiils.py</p>
  <pre><code>def cartData(request):
  if request.user.is_authenticated:
      user = request.user
      order, created = Order.objects.get_or_create(user=user, complete=False)
      items = order.orderitem_set.all()
      cartItems = order.get_cart_items
  else:
      cookieData = cookieCart(request)
      cartItems = cookieData['cartItems']
      order = cookieData['order']
      items = cookieData['items']
  
  return {'cartItems':cartItems ,'order':order, 'items':items}
  </code></pre>