Blogger Template by Blogcrowds.

django dynamic menu

Introduction:
     This section will teach you to How to create dynamic menu in templates. Here we used ``context processors``

Method:

  • create a file say `context_processors.py` inside your application folder.
  • File looks like
from models import GameCategory
def Category(request):
    category_list=list(GameCategory.objects.all())
    return {'category_list':category_list}
  • In Settings.py
TEMPLATE_CONTEXT_PROCESSORS = (
    'MyProject.MyApplication.context_processors.Category', # path to above-said file(context_processors.py)
)
  • Now you can able to get the {{category_list}} in your Base.html

0 Comments:

Post a Comment



Newer Post Older Post Home