Bläddra i källkod

Added an example to use the GET and URL parameters

Roland Haroutiounian 8 år sedan
förälder
incheckning
d05fa7ad78

+ 5
- 0
plugins/webui/interface/controllers/base.py Visa fil

@@ -22,5 +22,10 @@ def not_found(request):
22 22
 
23 23
 
24 24
 def test(request):
25
+    template_vars = {
26
+        'id': request.url_args['id'],
27
+        'params': request.GET
28
+    }
29
+    return get_response('test.html', tpl_vars=template_vars)
25 30
     return get_response('test.html')
26 31
     

+ 1
- 1
plugins/webui/interface/controllers/document.py Visa fil

@@ -2,5 +2,5 @@ from .base import get_response
2 2
 
3 3
 
4 4
 def show_document(request):
5
-    template_vars = {'id': request.url_args[0]}
5
+    template_vars = {'id': request.url_args['id']}
6 6
     return get_response('documents/show.html', tpl_vars=template_vars)

+ 1
- 1
plugins/webui/interface/router.py Visa fil

@@ -29,7 +29,7 @@ def get_controller(request):
29 29
         p = re.compile(regex)
30 30
         m = p.search(request.PATH)
31 31
         if m is not None:
32
-            request.url_args = m.groups()
32
+            request.url_args = m.groupdict()
33 33
             return callback
34 34
         '''match = re.search(regex, request.PATH)
35 35
         if match is not None:

+ 1
- 1
plugins/webui/interface/urls.py Visa fil

@@ -4,7 +4,7 @@ urls = (
4 4
     (r'^$', index),
5 5
     (r'admin/?$', admin),
6 6
     (r'admin/(.+)$', admin),
7
-    (r'test/(.+)$', test),
7
+    (r'test/(?P<id>.*)$', test),
8 8
     (r'test/?$', test),
9 9
     (r'show/(?P<id>.*)$', show_document),
10 10
     (r'list_classes/(.+)$', list_classes),

+ 7
- 0
plugins/webui/templates/test.html Visa fil

@@ -1,6 +1,13 @@
1 1
 <html>
2 2
 <head></head>
3 3
 <body>
4
+    URL arg : id = {{ id }}<br />
5
+    GET values :<br />
6
+    <ul>
7
+    {% for argument_name, argument_value in params.items() %}
8
+        <li>{{argument_name}} = {{ argument_value }}</li>
9
+    {% endfor %}
10
+    </ul>
4 11
     <form action="http://localhost:9090/admin?r=1&rand[]=7&rand[]=5" method="POST" enctype="multipart/form-data">
5 12
         <input type="text" name="re[]" value="3"><br />
6 13
         <input type="text" name="re[]" value="1"><br />

Loading…
Avbryt
Spara