from django.http import HttpResponse from django.shortcuts import get_object_or_404 from django.views.decorators.csrf import csrf_exempt from .models import ShortUrl @csrf_exempt def redirect_to_target(request, alias): short_url = get_object_or_404(ShortUrl, alias=alias) response = HttpResponse(status=307) response['Location'] = short_url.target return response