15 lines
384 B
Python
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
|