Files
url_shortener/short_url/views.py
2024-11-14 02:06:21 +08:00

15 lines
384 B
Python

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