I have a function shop_single in my views.py that has a variableLIST 'single_shop' that takes in shop_id as an argument from URLS.PY . How do i pass that variable 'single_shop ' to another function homepage and run another set of query on it.
views.py
def homepage(request):
cat1 = NewShop.objects.filter(category_id=1)
cat2 = NewShop.objects.filter(category_id=2)
cat3 = NewShop.objects.filter(category_id=3)
cat4 = NewShop.objects.filter(category_id=4)
name1 = ShopCategories.objects.filter(id=1)
name2 = ShopCategories.objects.filter(id=2)
name3 = ShopCategories.objects.filter(id=3)
name4 = ShopCategories.objects.filter(id=4)
return render_to_response('index.html',{'shop_name1': name1, 'shop_name2': name2, 'shop_name3': name3,
'shop_name4': name4, 'Shop_cat1': cat1, 'Shop_cat2': cat2,
'Shop_cat3': cat3,
'Shop_cat4': cat4,},)
def shop_single(request,shop_id):
single_shop = NewShop.objects.filter(id=shop_id)
cat1 = NewShop.objects.filter(category_id=1)
cat2 = NewShop.objects.filter(category_id=2)
cat3 = NewShop.objects.filter(category_id=3)
cat4 = NewShop.objects.filter(category_id=4)
name1 = ShopCategories.objects.filter(id=1)
name2 = ShopCategories.objects.filter(id=2)
name3 = ShopCategories.objects.filter(id=3)
name4 = ShopCategories.objects.filter(id=4)
for shop_id in single_shop:
return render_to_response('shop_single.html', {'shop_name1': name1, 'shop_name2': name2, 'shop_name3': name3,
'shop_name4': name4, 'Shop_cat1': cat1, 'Shop_cat2': cat2,
'Shop_cat3': cat3,'Shop_cat4': cat4,
'shop_id': single_shop, },)
else:
return homepage(request)
urls.py
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', views.homepage, name='homepage'),
url(r'^about/', views.about, name='about'),
url(r'^allshops/', views.allshops, name='all-shops'),
url(r'^shops/(?P<shop_id>[0-9]+)/$', views.shop_single, name='single-shop')