This commit is contained in:
2024-11-14 02:06:21 +08:00
commit 29ce03dbc5
24 changed files with 1042 additions and 0 deletions

14
short_url/views.py Normal file
View File

@ -0,0 +1,14 @@
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