[Fixed]-Django view variable matching to a queryset

1👍

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) 
    }

Leave a comment