Reputation: 12197
Sorry if the title doesn't make sense, but I didn't know how else to word it, first I will show you my code.
def page(request, page_lang='eng', page_title='home'):
page_lang = SiteLanguage.objects.get(title=page_lang)
context = {
'page_lang': page_lang,
'page_content': page_lang.page_title
}
So in my context I want to have the key 'page_content' match with the value page_lang.home so I can avoid putting a bunch of logic into the code. Can this be done?
Upvotes: 0
Views: 55
Reputation: 37934
you have to use getattr() and page_lang
should be renamed to page_lang_name
def page(request, page_lang_name='eng', page_title='home'):
page_lang_obj = SiteLanguage.objects.get(title=page_lang_name)
context = {
'page_lang': page_lang_obj,
'page_content': getattr(page_lang_obj, page_title)
}
Upvotes: 1