-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest_project.py
executable file
·75 lines (56 loc) · 1.55 KB
/
test_project.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
from __future__ import unicode_literals
import django
from django.conf import settings
from django.conf.urls import url
from django.http import HttpResponse, HttpResponseRedirect
# Configuration
if not settings.configured:
settings.configure(
DEBUG=True,
ROOT_URLCONF=__name__,
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
},
MIDDLEWARE_CLASSES=[
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'turbolinks.middleware.TurbolinksMiddleware'
],
INSTALLED_APPS=[
'django.contrib.sessions',
'turbolinks',
],
)
# Django >=1.7 compatibility
if hasattr(django, 'setup'):
django.setup()
# URL Router
urlpatterns = []
def route(regex):
def inner(view):
urlpatterns.append(url(regex, view))
return view
return inner
# Views
@route(r'^$')
def index(request):
return HttpResponse(request.META.get('HTTP_REFERER', ''))
@route(r'^page/$')
def page(request):
return HttpResponse('page')
@route(r'^redirect/$')
def redirect(request):
return HttpResponseRedirect('/page/')
@route(r'^x-redirect/$')
def x_redirect(request):
return HttpResponseRedirect('http://example.com')
# CLI
def main():
from django.core.management import execute_from_command_line
execute_from_command_line()
if __name__ == '__main__':
main()