0

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')
Daniel Kilanko
  • 110
  • 1
  • 11
  • http://stackoverflow.com/questions/17057191/flask-redirect-while-passing-arguments – Smizz Feb 23 '17 at 23:03
  • I have read that before, infact.. still trying to understand the explanation there.But i dont seem to get it yet. I might be silly.. i'm barely 1 month into Django and i know i have a lot of mistakes to make and alot to learn likewise.. – Daniel Kilanko Feb 23 '17 at 23:10
  • Look at [this answer](http://stackoverflow.com/a/31707946/4974980) - you can use `session` to store data between requests. – Jens Astrup Feb 24 '17 at 00:16
  • Possible duplicate of [How do I pass variables from one view to another and render with the last view's URL in Django?](http://stackoverflow.com/questions/31707546/how-do-i-pass-variables-from-one-view-to-another-and-render-with-the-last-views) – Jens Astrup Feb 24 '17 at 00:18
  • Possible duplicate of [Flask: redirect while passing arguments?](http://stackoverflow.com/questions/17057191/flask-redirect-while-passing-arguments) – David C. Feb 24 '17 at 01:06

0 Answers0