- 
                Notifications
    You must be signed in to change notification settings 
- Fork 262
Open
Labels
Description
Probably a personal preference, but I like to have values already set or calculated before the return is called. This example from Django, as part of a typical views module:
def some_view(request):
    """Some description."""
    # ... some processing
    context = dict(
        admin.site.each_context(request),
        query='hard_coded',
        query_fields=some_fn('param'))
    return render(
        request=request,
        template_name='query/query.html',
        context=context)
The context can contain many variables, and I think its easier for readability and debugging purposes to create/set all of its values before the return is called; it is an extra variable but I find the trade-off is worth it.