In the code below, all possible exit paths from the view return a response. It is only different from the default response, when you match the slug for a custom page:
def custom_page(request, slug):
context = {
'all': CustomPage.objects.filter(slug=slug),
'toBePublished': CustomPage.objects.all()
}
custom_pages = CustomPage.objects.all()
for page in custom_pages:
if page.slug == slug:
return render(request, 'member/custom_page.html', context)
# ends the search with no match
return render(request, 'member/home.html',context)
CLICK HERE to find out more related problems solutions.