diff --git a/examples/cherry_hello_world.py b/examples/cherry_hello_world.py index 9466182..51d80d7 100644 --- a/examples/cherry_hello_world.py +++ b/examples/cherry_hello_world.py @@ -4,7 +4,10 @@ import cherrypy class HelloWorld(object): @cherrypy.expose def index(self): - return "Hello World!" + with open('./templates/index.html') as fh: + index_f = fh.read() + result = index_f.format(_title='Nazev_stranky', _nadpis='Cokoliv!') + return result cherrypy.quickstart(HelloWorld()) diff --git a/examples/chttpd.py b/examples/chttpd.py index 814443b..5e1d4b4 100755 --- a/examples/chttpd.py +++ b/examples/chttpd.py @@ -28,7 +28,7 @@ def main_server_loop(): *Exception* If server is unable to start ''' - server_config={ + server_config = { 'server.socket_host': '127.0.0.1', 'server.socket_port': 80 } diff --git a/examples/modules/index.py b/examples/modules/index.py index f15468e..701e7e5 100644 --- a/examples/modules/index.py +++ b/examples/modules/index.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 import cherrypy -import config +import json static_dir = '/templates/' # Needs to have trailing and leading slash '/' @@ -8,5 +8,37 @@ class wellcome(object): '''Base Index constructor and expose function''' @cherrypy.expose def index(self): - result = '

Wellcome

' + result = '''{ + "firstName": "John", + "lastName": "Smith", + "isAlive": true, + "age": 27, + "address": { + "streetAddress": "21 2nd Street", + "city": "New York", + "state": "NY", + "postalCode": "10021-3100" + }, + "phoneNumbers": [ + { + "type": "home", + "number": "212 555-1234" + }, + { + "type": "office", + "number": "646 555-4567" + }, + { + "type": "mobile", + "number": "123 456-7890" + } + ], + "children": [], + "spouse": null + }''' + return json.loads(result) + + @cherrypy.expose + def other(self): + result = '

Other

' return result diff --git a/examples/templates/index.html b/examples/templates/index.html new file mode 100644 index 0000000..0944353 --- /dev/null +++ b/examples/templates/index.html @@ -0,0 +1,10 @@ + + +{_title} + + +
+

{_nadpis}!

+
+ +