Difference between revisions of "Passing an integer through the url to make a product page"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "We will make it so the product is passed through the url, and then used to display just that product. So we could use'/product/1' to display the produce with the id number of...")
 
(urls.py)
Line 3: Line 3:
 
=urls.py=
 
=urls.py=
  
We need to define a new path in the 'urlpatterns':
+
We need to define a new path in the 'urlpatterns', add the following:
 +
 
 +
<syntaxhighlight lang=python>
 +
path('product/<int:prodID>/', myapp.views.showproduct, name='showproduct'),
 +
</syntaxhighlight>
 +
 
 +
This will create a url for '/product/' and the value you enter, ie '/product/1' will be used as an integer and will be called 'prodID'.
  
 
=views.py=
 
=views.py=
  
 
=template=
 
=template=

Revision as of 14:15, 26 September 2019

We will make it so the product is passed through the url, and then used to display just that product. So we could use'/product/1' to display the produce with the id number of 1.

urls.py

We need to define a new path in the 'urlpatterns', add the following:

path('product/<int:prodID>/', myapp.views.showproduct, name='showproduct'),

This will create a url for '/product/' and the value you enter, ie '/product/1' will be used as an integer and will be called 'prodID'.

views.py

template