Commit e5f55656 authored by Jean Michel Rouly's avatar Jean Michel Rouly

Added redirection.

parent 21d465e5
from go.models import URL
from django.http import Http404
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, get_object_or_404, redirect
......@@ -45,3 +46,15 @@ def signup(request):
},
)
# Redirection view.
def redirection(request, short):
try:
url = URL.objects.get( short = short )
except URL.DoesNotExist:
raise Http404("Target URL not found.")
target = url.target
url.clicks = url.clicks + 1
url.save()
return redirect( target )
......@@ -32,3 +32,8 @@ urlpatterns += patterns('django.contrib.auth.views',
url(r'^logout$', 'logout', {'next_page' : '/'},
name='go_logout'),
)
urlpatterns += patterns('go.views',
# Redirection regex.
url(r'^(?P<short>\w+)$', 'redirection', name = 'redirection'),
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment