-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathviews.py
38 lines (26 loc) · 1.11 KB
/
views.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
from mini_django import HttpRequest, HttpResponse
# This is similar to Django's views.py
def root(req: HttpRequest) -> HttpResponse:
res = HttpResponse()
res.headers['Content-Type'] = 'text/html; charset=utf-8'
res.write("<!DOCTYPE html>")
res.write("<html><head></head><body>")
res.write("<p>mini_django seems to be working!</p>")
res.write("<p>This is the page at the root path, try another path</p>")
res.write("<p>Try /dj4e /js4e or generate errors with /missing or /broken</p>")
res.write("</body></html>")
return res
def dj4e(req: HttpRequest) -> HttpResponse:
res = HttpResponse()
res.headers['Content-Type'] = 'text/plain; charset=utf-8'
res.write("Django is fun")
return res
def js4e(req: HttpRequest) -> HttpResponse:
res = HttpResponse()
res.code = "302" # Lets do a temporary redirect...
res.headers['Location'] = '/dj4e'
res.headers['Content-Type'] = 'text/plain; charset=utf-8'
res.write("You will only see this in the debugger!")
return res
def broken(req: HttpRequest):
return "I am a broken view, returning a string by mistake"