first working version
This commit is contained in:
parent
3372200219
commit
a3c55fd975
4 changed files with 23 additions and 7 deletions
|
@ -12,7 +12,7 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<nav class="navbar navbar-dark bg-dark">
|
<nav class="navbar navbar-dark bg-dark">
|
||||||
<h1>Litl.</h1>
|
<a class="navbar-brand mb-0 h1" href="/">Litl.</a>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
9
litl/templates/unknown.html
Normal file
9
litl/templates/unknown.html
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container text-center">
|
||||||
|
<div class="container">
|
||||||
|
<h2><p class="text-danger"><b>litl.auro.re/{{slug}}</b></p> Is not a valid entry for this instance of litl.</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -16,12 +16,13 @@ Including another URLconf
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from .views import index, AddSlug, display
|
from .views import index, AddSlug, display, redirect
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
#path('', index, name="index"),
|
#path('', index, name="index"),
|
||||||
path('', AddSlug, name="index"),
|
path('', AddSlug, name="index"),
|
||||||
#path(r"^display/(?P<slug_slug>[a-zA-Z0-9]+)$", display, name="display"),
|
#path(r"^display/(?P<slug_slug>[a-zA-Z0-9]+)$", display, name="display"),
|
||||||
path('display/<slug:slug>/', display, name='display'),
|
path('display/<slug:slug_got>/', display, name='display'),
|
||||||
|
path('<slug:slug_got>/', redirect, name='redirect'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -36,12 +36,18 @@ def AddSlug(request):
|
||||||
form = SlugAddForm()
|
form = SlugAddForm()
|
||||||
return render(request,'add_slug.html',{'form':form})
|
return render(request,'add_slug.html',{'form':form})
|
||||||
|
|
||||||
def display(request, slug):
|
def display(request, slug_got):
|
||||||
slug = Slug.objects.filter(slug = slug).all()
|
slug = Slug.objects.filter(slug = slug_got).all()
|
||||||
if slug.count()!=1:
|
if slug.count()!=1:
|
||||||
# TODO Redirect to 'unknown and display a message
|
return render(request,'unknown.html',{'slug':slug_got})
|
||||||
return HttpResponsRedirect('display')
|
|
||||||
else:
|
else:
|
||||||
context = {'slug':slug.get()}
|
context = {'slug':slug.get()}
|
||||||
return render(request,'display.html',context)
|
return render(request,'display.html',context)
|
||||||
|
|
||||||
|
def redirect(request,slug_got):
|
||||||
|
slug = Slug.objects.filter(slug = slug_got).all()
|
||||||
|
if slug.count()!=1:
|
||||||
|
return render(request,'unknown.html',{'slug':slug_got})
|
||||||
|
else:
|
||||||
|
return HttpResponseRedirect(slug.get().destination)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue