[Fixed]-Django: Returning a customized view function

1👍

you could do the routing inside your view function, e.g.:

def dashboard(request):
    if request.user.company == 'foo':
        return dashboard_foo(request)
    elif request.user.company == 'bar':
        return dashboard_bar(request)
    else:
        return dashboard_standard(request)

Depending on the complexity of your view it might make sense to use a class based view, so you only need to swap out the specific logic (e.g.: templates, context vars, etc.) in the specific methods, and let the main logic be the same across all users (i.e.: reduce code duplication).

👤zsepi

Leave a comment