Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions l2l/templates/l2l/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load static %}
{#{% load l2l_extras %}#}
{% load l2l_extras %}
<!doctype html>
<html lang="en">
<head>
Expand Down Expand Up @@ -57,8 +57,8 @@ <h1 class="display-4 fw-normal">Punny headline</h1>
<p class="lead fw-normal">Yes this is a rip-off from one of Bootstrap's example html pages.</p>
<p class="lead fw-normal">Today's date is: {{ now }}</p>
<p class="lead fw-normal">Today's ISO date is: {{ iso }}</p>
{#<p class="lead fw-normal">Today's date from a date is: {{ now|l2l_dt }}</p>#}
{#<p class="lead fw-normal">Today's date from a string is: {{ iso|l2l_dt }}</p>#}
<p class="lead fw-normal">Today's date from a date is: {{ now|l2l_dt }}</p>
<p class="lead fw-normal">Today's date from a string is: {{ iso|l2l_dt }}</p>
<a class="btn btn-outline-secondary" href="#">Coming soon</a>
</div>
<div class="product-device shadow-sm d-none d-md-block"></div>
Expand Down
22 changes: 22 additions & 0 deletions l2l/templatetags/l2l_extras.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django import template
from datetime import datetime

register = template.Library()

DATE_FORMAT = "%Y-%m-%dT%H:%M:%S"
STRING_DATE_FORMAT = "%Y-%m-%d %H:%M:%S"



@register.filter
def l2l_dt(date):
if isinstance(date, datetime):
return date.strftime(STRING_DATE_FORMAT)

if isinstance(date, str):
try:
parsed_date = datetime.strptime(date, DATE_FORMAT)
return parsed_date.strftime(STRING_DATE_FORMAT)
except ValueError:
return date
return None
3 changes: 1 addition & 2 deletions testsite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

from socket import gethostname, gethostbyname
ALLOWED_HOSTS = [gethostname(), gethostbyname(gethostname()), 'localhost']
ALLOWED_HOSTS = ['localhost', '127.0.0.1', '0.0.0.0']


# Application definition
Expand Down