first working version

This commit is contained in:
grisel-davy 2020-12-30 18:48:14 +01:00
parent 3372200219
commit a3c55fd975
4 changed files with 23 additions and 7 deletions

View file

@ -12,7 +12,7 @@
<body>
<nav class="navbar navbar-dark bg-dark">
<h1>Litl.</h1>
<a class="navbar-brand mb-0 h1" href="/">Litl.</a>
</nav>
<div class="container">

View 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 %}

View file

@ -16,12 +16,13 @@ Including another URLconf
from django.contrib import admin
from django.urls import path
from .views import index, AddSlug, display
from .views import index, AddSlug, display, redirect
urlpatterns = [
path('admin/', admin.site.urls),
#path('', index, name="index"),
path('', AddSlug, name="index"),
#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'),
]

View file

@ -36,12 +36,18 @@ def AddSlug(request):
form = SlugAddForm()
return render(request,'add_slug.html',{'form':form})
def display(request, slug):
slug = Slug.objects.filter(slug = slug).all()
def display(request, slug_got):
slug = Slug.objects.filter(slug = slug_got).all()
if slug.count()!=1:
# TODO Redirect to 'unknown and display a message
return HttpResponsRedirect('display')
return render(request,'unknown.html',{'slug':slug_got})
else:
context = {'slug':slug.get()}
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)