1

I am currently using Django and Oscar to set up a shopping cart for someone.

I am also using the django-oscar-stores extension.

I was wondering if there is a way for me to incorporate the context of a django-oscar-stores view in to my other views and templates so I can use the variables to dynamically add the store information to the site.

So if I go to the view of the stores app I can call a variable in that template {{ store_list }} but if I am in any other view I cannot access this variable.

I understand why I cannot, but I was wondering how I would give access to the store_list variable so that I can use it on every page (so I can have the store information in the header of the site dynamically and not hard coded in to the template).

I am new to Django, so sorry if this is a dumb question.

noub
  • 103
  • 1
  • 6

1 Answers1

0

If you want to pass a variable to a specific template from your view function, you should use context kwargs, in django's render shortcut.

    return render(request, 'index.html', context={'store_list': store_list_var})

If you want to pass it to all templates, use context_processors.

Or Duan
  • 13,142
  • 6
  • 60
  • 65
  • 1
    Thanks a ton, context_processors was exactly what I needed. I already have it up and running and now the variables are accessible across the whole site. Thanks again. – noub Jul 12 '17 at 20:08