-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_urls.py
57 lines (51 loc) · 1.6 KB
/
test_urls.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
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import
from django.conf.urls import url, include
from django.contrib import admin
from django.forms import Form
from django.http import HttpResponse
from django.template import Template, Context
from templateselector.fields import TemplateChoiceField
def example(request):
class MyForm1(Form):
field = TemplateChoiceField(match="^admin/[0-9]+.html$")
class MyForm2(Form):
field = TemplateChoiceField(match="^admin/404.html$")
class MyForm3(Form):
field = TemplateChoiceField(match="^admin/_doesnt_exist_.html$")
context = {
'forms': (
MyForm1(request.GET or None, prefix='form1'),
MyForm2(request.GET or None, prefix='form2'),
MyForm3(request.GET or None, prefix='form3'),
)
}
template = Template("""<!DOCTYPE html>
<html><head>
<title>django-templateselector</title>
{{ forms.0.media }}</head>
<body>
<form action="" method="GET" accept-charset="utf-8">
{% for form in forms %}
<div style="background-color: #FFF; border-bottom: 1px solid #DDD; padding: 1rem;">
{{ form.field }}
{{ form.field.errors }}
</div>
{% endfor %}
<input type="submit" value="Click!">
</form>
</body>
</html>
""")
return HttpResponse(template.render(Context(context)))
urlpatterns = [
url('^admin/', include(admin.site.urls)),
url('^$', example),
]
try:
import debug_toolbar
urlpatterns = [
url(r'^__debug__/', include(debug_toolbar.urls)),
] + urlpatterns
except ImportError:
pass