from comics.sets.models import UserSet

def user_set(request):
    try:
        user_set = UserSet.objects.get(user=request.user)
        return {
            'user_set': user_set,
            'user_set_comics': user_set.comics.all(),
        }
    except UserSet.DoesNotExist:
        return {}

def user_set(request):
    if hasattr(request, 'user_set'):
        return {
            'user_set': request.user_set,
            'user_set_comics': request.user_set.comics.all(),
        }
    else:
        return {}

Use request.user_set in context preprocessor
Use request.user_set in context preprocessor

- from comics.sets.models import UserSet
- 
  def user_set(request):
+     if hasattr(request, 'user_set'):
-     try:
-         user_set = UserSet.objects.get(user=request.user)
          return {
-             'user_set': user_set,
+             'user_set': request.user_set,
-             'user_set_comics': user_set.comics.all(),
+             'user_set_comics': request.user_set.comics.all(),
          }
-     except UserSet.DoesNotExist:
+     else:
          return {}
  
Use request.user_set in context preprocessor
## Code Before:
from comics.sets.models import UserSet

def user_set(request):
    try:
        user_set = UserSet.objects.get(user=request.user)
        return {
            'user_set': user_set,
            'user_set_comics': user_set.comics.all(),
        }
    except UserSet.DoesNotExist:
        return {}

## Instruction:
Use request.user_set in context preprocessor
## Code After:
def user_set(request):
    if hasattr(request, 'user_set'):
        return {
            'user_set': request.user_set,
            'user_set_comics': request.user_set.comics.all(),
        }
    else:
        return {}
