python - how to Pass variable in link to the django view -
i have html form display data using loop.
<tbody id="table"> {% sku, lid, stk, mrp, sp, stts in product_data %} <tr> <td> <a class="btn-link" href="/product/product.html" value="{{sku}}">{{sku}}</a> </td> <td>{{lid}}</td> .....
this code prints data in table using loop link in first colyumn of table.
link points new page want data displayed.
displayed data dynamically generated mongodb database. want when click on link pass value parametre django view can fetch data contains parametre , show on next page. how that?
my views.py:
from django.shortcuts import render django.http import httpresponse inventory.models import getproductdata def inventory(request): pd = getproductdata().skudata() sku = pd[0] listing_id = pd[1] stock_count = pd[2] mrp = pd[3] status = pd[5] selling_price = pd[4] product_data = zip(sku, listing_id, stock_count, mrp, selling_price, status) context_dict = {'product_data':product_data} return render(request, 'inventory/inventory.html', context_dict) def product(request): return render(request, 'inventory/product.html')
first of all, not advisable use html name when add url. instead of having
href="/product/product.html"
you have had like
href="/product/"
so in urls.py should have defined below
url(r'^product/$', product),
where 'product ' corresponding view handling request.
now if want send parameters django html
render template below
<tbody id="table"> {% sku, lid, stk, mrp, sp, stts in product_data %} <tr> <td> <a class="btn-link" href="/product/?sku={{ sku }}">{{sku}}</a> </td> <td>{{lid}}</td> .....
and in view i.e; @ products
def product(request): if request.method=='get': sku = request.get.get('sku') if not sku: return render(request, 'inventory/product.html') else: # have value of sku # can continue rest return render(request, 'some_other.html')
Comments
Post a Comment