-
Notifications
You must be signed in to change notification settings - Fork 0
/
tinyapp.py
43 lines (33 loc) · 915 Bytes
/
tinyapp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# tinyapp.py
from django.urls import re_path
from django.shortcuts import redirect, render as django_render
DEBUG = True
SECRET_KEY = '1234'
ROOT_URLCONF = __name__
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
'templates/'
],
},
]
# wrapper renders django template
def render(template_name):
def decorator(func):
def wrapper(request, *args, **kwargs):
context = func(request, *args, **kwargs)
return django_render(request, template_name, context)
return wrapper
return decorator
@render(template_name='about.html')
def about(request):
title = 'Tinyapp'
author = 'John Mitchell'
return locals()
def home(request):
return redirect('aboutpage')
urlpatterns = [
re_path(r'^$', home, name='homepage'),
re_path(r'^about/$', about, name='aboutpage'),
]