/usr/share/doc/python-cherrypy3-doc/html/_sources/basics.rst.txt is in python-cherrypy3-doc 8.9.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 | .. _basics:
Basics
------
The following sections will drive you through the basics of
a CherryPy application, introducing some essential concepts.
.. contents::
:depth: 4
The one-minute application example
##################################
The most basic application you can write with CherryPy
involves almost all its core concepts.
.. code-block:: python
:linenos:
import cherrypy
class Root(object):
@cherrypy.expose
def index(self):
return "Hello World!"
if __name__ == '__main__':
cherrypy.quickstart(Root(), '/')
First and foremost, for most tasks, you will never need more than
a single import statement as demonstrated in line 1.
Before discussing the meat, let's jump to line 9 which shows,
how to host your application with the CherryPy application server
and serve it with its builtin HTTP server at the `'/'` path.
All in one single line. Not bad.
Let's now step back to the actual application. Even though CherryPy
does not mandate it, most of the time your applications
will be written as Python classes. Methods of those classes will
be called by CherryPy to respond to client requests. However,
CherryPy needs to be aware that a method can be used that way, we
say the method needs to be :term:`exposed`. This is precisely
what the :func:`cherrypy.expose()` decorator does in line 4.
Save the snippet in a file named `myapp.py` and run your first
CherryPy application:
.. code-block:: bash
$ python myapp.py
Then point your browser at http://127.0.0.1:8080. Tada!
.. note::
CherryPy is a small framework that focuses on one single task:
take a HTTP request and locate the most appropriate
Python function or method that match the request's URL.
Unlike other well-known frameworks, CherryPy does not
provide a built-in support for database access, HTML
templating or any other middleware nifty features.
In a nutshell, once CherryPy has found and called an
:term:`exposed` method, it is up to you, as a developer, to
provide the tools to implement your application's logic.
CherryPy takes the opinion that you, the developer, know best.
.. warning::
The previous example demonstrated the simplicty of the
CherryPy interface but, your application will likely
contain a few other bits and pieces: static service,
more complex structure, database access, etc.
This will be developed in the tutorial section.
CherryPy is a minimal framework but not a bare one, it comes
with a few basic tools to cover common usages that you would
expect.
Hosting one or more applications
################################
A web application needs an HTTP server to be accessed to. CherryPy
provides its own, production ready, HTTP server. There are two
ways to host an application with it. The simple one and the almost-as-simple one.
Single application
^^^^^^^^^^^^^^^^^^
The most straightforward way is to use :func:`cherrypy.quickstart`
function. It takes at least one argument, the instance of the
application to host. Two other settings are optionals. First, the
base path at which the application will be accessible from. Second,
a config dictionary or file to configure your application.
.. code-block:: python
cherrypy.quickstart(Blog())
cherrypy.quickstart(Blog(), '/blog')
cherrypy.quickstart(Blog(), '/blog', {'/': {'tools.gzip.on': True}})
The first one means that your application will be available at
http://hostname:port/ whereas the other two will make your blog
application available at http://hostname:port/blog. In addition,
the last one provides specific settings for the application.
.. note::
Notice in the third case how the settings are still
relative to the application, not where it is made available at,
hence the `{'/': ... }` rather than a `{'/blog': ... }`
Multiple applications
^^^^^^^^^^^^^^^^^^^^^
The :func:`cherrypy.quickstart` approach is fine for a single application,
but lacks the capacity to host several applications with the server.
To achieve this, one must use the :meth:`cherrypy.tree.mount <cherrypy._cptree.Tree.mount>`
function as follows:
.. code-block:: python
cherrypy.tree.mount(Blog(), '/blog', blog_conf)
cherrypy.tree.mount(Forum(), '/forum', forum_conf)
cherrypy.engine.start()
cherrypy.engine.block()
Essentially, :meth:`cherrypy.tree.mount <cherrypy._cptree.Tree.mount>`
takes the same parameters as :func:`cherrypy.quickstart`: an :term:`application`,
a hosting path segment and a configuration. The last two lines
are simply starting application server.
.. important::
:func:`cherrypy.quickstart` and :meth:`cherrypy.tree.mount <cherrypy._cptree.Tree.mount>`
are not exclusive. For instance, the previous lines can be written as:
.. code-block:: python
cherrypy.tree.mount(Blog(), '/blog', blog_conf)
cherrypy.quickstart(Forum(), '/forum', forum_conf)
.. note::
You can also :ref:`host foreign WSGI application <hostwsgiapp>`.
Logging
#######
Logging is an important task in any application. CherryPy will
log all incoming requests as well as protocol errors.
To do so, CherryPy manages two loggers:
- an access one that logs every incoming requests
- an application/error log that traces errors or other application-level messages
Your application may leverage that second logger by calling
:func:`cherrypy.log() <cherrypy._cplogging.LogManager.error>`.
.. code-block:: python
cherrypy.log("hello there")
You can also log an exception:
.. code-block:: python
try:
...
except:
cherrypy.log("kaboom!", traceback=True)
Both logs are writing to files identified by the following keys
in your configuration:
- ``log.access_file`` for incoming requests using the
`common log format <http://en.wikipedia.org/wiki/Common_Log_Format>`_
- ``log.error_file`` for the other log
.. seealso::
Refer to the :mod:`cherrypy._cplogging` module for more
details about CherryPy's logging architecture.
Disable logging
^^^^^^^^^^^^^^^
You may be interested in disabling either logs.
To disable file logging, simply set a en empty string to the
``log.access_file`` or ``log.error_file`` keys in your
:ref:`global configuration <globalsettings>`.
To disable, console logging, set ``log.screen`` to `False`.
.. code-block:: python
cherrypy.config.update({'log.screen': False,
'log.access_file': '',
'log.error_file': ''})
Play along with your other loggers
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Your application may obviously already use the :mod:`logging`
module to trace application level messages. Below is a simple
example on setting it up.
.. code-block:: python
import logging
import logging.config
import cherrypy
logger = logging.getLogger()
db_logger = logging.getLogger('db')
LOG_CONF = {
'version': 1,
'formatters': {
'void': {
'format': ''
},
'standard': {
'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
},
},
'handlers': {
'default': {
'level':'INFO',
'class':'logging.StreamHandler',
'formatter': 'standard',
'stream': 'ext://sys.stdout'
},
'cherrypy_console': {
'level':'INFO',
'class':'logging.StreamHandler',
'formatter': 'void',
'stream': 'ext://sys.stdout'
},
'cherrypy_access': {
'level':'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'void',
'filename': 'access.log',
'maxBytes': 10485760,
'backupCount': 20,
'encoding': 'utf8'
},
'cherrypy_error': {
'level':'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'void',
'filename': 'errors.log',
'maxBytes': 10485760,
'backupCount': 20,
'encoding': 'utf8'
},
},
'loggers': {
'': {
'handlers': ['default'],
'level': 'INFO'
},
'db': {
'handlers': ['default'],
'level': 'INFO' ,
'propagate': False
},
'cherrypy.access': {
'handlers': ['cherrypy_access'],
'level': 'INFO',
'propagate': False
},
'cherrypy.error': {
'handlers': ['cherrypy_console', 'cherrypy_error'],
'level': 'INFO',
'propagate': False
},
}
}
class Root(object):
@cherrypy.expose
def index(self):
logger.info("boom")
db_logger.info("bam")
cherrypy.log("bang")
return "hello world"
if __name__ == '__main__':
cherrypy.config.update({'log.screen': False,
'log.access_file': '',
'log.error_file': ''})
cherrypy.engine.unsubscribe('graceful', cherrypy.log.reopen_files)
logging.config.dictConfig(LOG_CONF)
cherrypy.quickstart(Root())
In this snippet, we create a `configuration dictionary <https://docs.python.org/2/library/logging.config.html#logging.config.dictConfig>`_
that we pass on to the ``logging`` module to configure
our loggers:
* the default root logger is associated to a single stream handler
* a logger for the db backend with also a single stream handler
In addition, we re-configure the CherryPy loggers:
* the top-level ``cherrypy.access`` logger to log requests into a file
* the ``cherrypy.error`` logger to log everything else into a file
and to the console
We also prevent CherryPy from trying to open its log files when
the autoreloader kicks in. This is not strictly required since we do not
even let CherryPy open them in the first place. But, this avoids
wasting time on something useless.
.. _config:
Configuring
###########
CherryPy comes with a fine-grained configuration mechanism and
settings can be set at various levels.
.. seealso::
Once you have the reviewed the basics, please refer
to the :ref:`in-depth discussion <configindepth>`
around configuration.
.. _globalsettings:
Global server configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^
To configure the HTTP and application servers,
use the :meth:`cherrypy.config.update() <cherrypy._cpconfig.Config.update>`
method.
.. code-block:: python
cherrypy.config.update({'server.socket_port': 9090})
The :mod:`cherrypy.config <cherrypy._cpconfig>` object is a dictionary and the
update method merges the passed dictionary into it.
You can also pass a file instead (assuming a `server.conf`
file):
.. code-block:: ini
[global]
server.socket_port: 9090
.. code-block:: python
cherrypy.config.update("server.conf")
.. warning::
:meth:`cherrypy.config.update() <cherrypy._cpconfig.Config.update>`
is not meant to be used to configure the application.
It is a common mistake. It is used to configure the server and engine.
.. _perappconf:
Per-application configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
To configure your application, pass in a dictionary or a file
when you associate your application to the server.
.. code-block:: python
cherrypy.quickstart(myapp, '/', {'/': {'tools.gzip.on': True}})
or via a file (called `app.conf` for instance):
.. code-block:: ini
[/]
tools.gzip.on: True
.. code-block:: python
cherrypy.quickstart(myapp, '/', "app.conf")
Although, you can define most of your configuration in a global
fashion, it is sometimes convenient to define them
where they are applied in the code.
.. code-block:: python
class Root(object):
@cherrypy.expose
@cherrypy.tools.gzip()
def index(self):
return "hello world!"
A variant notation to the above:
.. code-block:: python
class Root(object):
@cherrypy.expose
def index(self):
return "hello world!"
index._cp_config = {'tools.gzip.on': True}
Both methods have the same effect so pick the one
that suits your style best.
Additional application settings
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You can add settings that are not specific to a request URL
and retrieve them from your page handler as follows:
.. code-block:: ini
[/]
tools.gzip.on: True
[googleapi]
key = "..."
appid = "..."
.. code-block:: python
class Root(object):
@cherrypy.expose
def index(self):
google_appid = cherrypy.request.app.config['googleapi']['appid']
return "hello world!"
cherrypy.quickstart(Root(), '/', "app.conf")
Cookies
#######
CherryPy uses the :mod:`Cookie` module from python and in particular the
:class:`Cookie.SimpleCookie` object type to handle cookies.
- To send a cookie to a browser, set ``cherrypy.response.cookie[key] = value``.
- To retrieve a cookie sent by a browser, use ``cherrypy.request.cookie[key]``.
- To delete a cookie (on the client side), you must *send* the cookie with its
expiration time set to `0`:
.. code-block:: python
cherrypy.response.cookie[key] = value
cherrypy.response.cookie[key]['expires'] = 0
It's important to understand that the request cookies are **not** automatically
copied to the response cookies. Clients will send the same cookies on every
request, and therefore ``cherrypy.request.cookie`` should be populated each
time. But the server doesn't need to send the same cookies with every response;
therefore, ``cherrypy.response.cookie`` will usually be empty. When you wish
to “delete” (expire) a cookie, therefore, you must set
``cherrypy.response.cookie[key] = value`` first, and then set its ``expires``
attribute to 0.
Extended example:
.. code-block:: python
import cherrypy
class MyCookieApp(object):
@cherrypy.expose
def set(self):
cookie = cherrypy.response.cookie
cookie['cookieName'] = 'cookieValue'
cookie['cookieName']['path'] = '/'
cookie['cookieName']['max-age'] = 3600
cookie['cookieName']['version'] = 1
return "<html><body>Hello, I just sent you a cookie</body></html>"
@cherrypy.expose
def read(self):
cookie = cherrypy.request.cookie
res = """<html><body>Hi, you sent me %s cookies.<br />
Here is a list of cookie names/values:<br />""" % len(cookie)
for name in cookie.keys():
res += "name: %s, value: %s<br>" % (name, cookie[name].value)
return res + "</body></html>"
if __name__ == '__main__':
cherrypy.quickstart(MyCookieApp(), '/cookie')
.. _basicsession:
Using sessions
##############
Sessions are one of the most common mechanism used by developers to
identify users and synchronize their activity. By default, CherryPy
does not activate sessions because it is not a mandatory feature
to have, to enable it simply add the following settings in your
configuration:
.. code-block:: ini
[/]
tools.sessions.on: True
.. code-block:: python
cherrypy.quickstart(myapp, '/', "app.conf")
Sessions are, by default, stored in RAM so, if you restart your server
all of your current sessions will be lost. You can store them in memcached
or on the filesystem instead.
Using sessions in your applications is done as follows:
.. code-block:: python
import cherrypy
@cherrypy.expose
def index(self):
if 'count' not in cherrypy.session:
cherrypy.session['count'] = 0
cherrypy.session['count'] += 1
In this snippet, everytime the the index page handler is called,
the current user's session has its `'count'` key incremented by `1`.
CherryPy knows which session to use by inspecting the cookie
sent alongside the request. This cookie contains the session
identifier used by CherryPy to load the user's session from
the storage.
.. seealso::
Refer to the :mod:`cherrypy.lib.sessions` module for more
details about the session interface and implementation.
Notably you will learn about sessions expiration.
Filesystem backend
^^^^^^^^^^^^^^^^^^
Using a filesystem is a simple to not lose your sessions
between reboots. Each session is saved in its own file within
the given directory.
.. code-block:: ini
[/]
tools.sessions.on: True
tools.sessions.storage_class = cherrypy.lib.sessions.FileSession
tools.sessions.storage_path = "/some/directory"
Memcached backend
^^^^^^^^^^^^^^^^^
`Memcached <http://memcached.org/>`_ is a popular key-store on top of your RAM,
it is distributed and a good choice if you want to
share sessions outside of the process running CherryPy.
Requires that the Python
`memcached <https://pypi.org/project/memcached>`_
package is installed, which may be indicated by installing
``cherrypy[memcached_session]``.
.. code-block:: ini
[/]
tools.sessions.on: True
tools.sessions.storage_class = cherrypy.lib.sessions.MemcachedSession
.. _staticontent:
Other backends
^^^^^^^^^^^^^^
Any other library may implement a session backend. Simply subclass
``cherrypy.lib.sessions.Session`` and indicate that subclass as
``tools.sessions.storage_class``.
Static content serving
######################
CherryPy can serve your static content such as images, javascript and
CSS resources, etc.
.. note::
CherryPy uses the :mod:`mimetypes` module to determine the
best content-type to serve a particular resource. If the choice
is not valid, you can simply set more media-types as follows:
.. code-block:: python
import mimetypes
mimetypes.types_map['.csv'] = 'text/csv'
Serving a single file
^^^^^^^^^^^^^^^^^^^^^
You can serve a single file as follows:
.. code-block:: ini
[/style.css]
tools.staticfile.on = True
tools.staticfile.filename = "/home/site/style.css"
CherryPy will automatically respond to URLs such as
`http://hostname/style.css`.
Serving a whole directory
^^^^^^^^^^^^^^^^^^^^^^^^^
Serving a whole directory is similar to a single file:
.. code-block:: ini
[/static]
tools.staticdir.on = True
tools.staticdir.dir = "/home/site/static"
Assuming you have a file at `static/js/my.js`,
CherryPy will automatically respond to URLs such as
`http://hostname/static/js/my.js`.
.. note::
CherryPy always requires the absolute path to the files or directories
it will serve. If you have several static sections to configure
but located in the same root directory, you can use the following
shortcut:
.. code-block:: ini
[/]
tools.staticdir.root = "/home/site"
[/static]
tools.staticdir.on = True
tools.staticdir.dir = "static"
Specifying an index file
^^^^^^^^^^^^^^^^^^^^^^^^^
By default, CherryPy will respond to the root of a static
directory with an 404 error indicating the path '/' was not found.
To specify an index file, you can use the following:
.. code-block:: ini
[/static]
tools.staticdir.on = True
tools.staticdir.dir = "/home/site/static"
tools.staticdir.index = "index.html"
Assuming you have a file at `static/index.html`,
CherryPy will automatically respond to URLs such as
`http://hostname/static/` by returning its contents.
Allow files downloading
^^^^^^^^^^^^^^^^^^^^^^^
Using ``"application/x-download"`` response content-type,
you can tell a browser that a resource should be downloaded
onto the user's machine rather than displayed.
You could for instance write a page handler as follows:
.. code-block:: python
from cherrypy.lib.static import serve_file
@cherrypy.expose
def download(self, filepath):
return serve_file(filepath, "application/x-download", "attachment")
Assuming the filepath is a valid path on your machine, the
response would be considered as a downloadable content by
the browser.
.. warning::
The above page handler is a security risk on its own since any file
of the server could be accessed (if the user running the
server had permissions on them).
Dealing with JSON
#################
CherryPy has built-in support for JSON encoding and decoding
of the request and/or response.
Decoding request
^^^^^^^^^^^^^^^^
To automatically decode the content of a request using JSON:
.. code-block:: python
class Root(object):
@cherrypy.expose
@cherrypy.tools.json_in()
def index(self):
data = cherrypy.request.json
The `json` attribute attached to the request contains
the decoded content.
Encoding response
^^^^^^^^^^^^^^^^^
To automatically encode the content of a response using JSON:
.. code-block:: python
class Root(object):
@cherrypy.expose
@cherrypy.tools.json_out()
def index(self):
return {'key': 'value'}
CherryPy will encode any content returned by your page handler
using JSON. Not all type of objects may natively be
encoded.
Authentication
##############
CherryPy provides support for two very simple authentication mechanisms,
both described in :rfc:`2617`: Basic and Digest. They are most commonly
known to trigger a browser's popup asking users their name
and password.
Basic
^^^^^
Basic authentication is the simplest form of authentication however
it is not a secure one as the user's credentials are embedded into
the request. We advise against using it unless you are running on
SSL or within a closed network.
.. code-block:: python
from cherrypy.lib import auth_basic
USERS = {'jon': 'secret'}
def validate_password(realm, username, password):
if username in USERS and USERS[username] == password:
return True
return False
conf = {
'/protected/area': {
'tools.auth_basic.on': True,
'tools.auth_basic.realm': 'localhost',
'tools.auth_basic.checkpassword': validate_password
}
}
cherrypy.quickstart(myapp, '/', conf)
Simply put, you have to provide a function that will
be called by CherryPy passing the username and password
decoded from the request.
The function can read its data from any source it has to: a file,
a database, memory, etc.
Digest
^^^^^^
Digest authentication differs by the fact the credentials
are not carried on by the request so it's a little more secure
than basic.
CherryPy's digest support has a similar interface to the
basic one explained above.
.. code-block:: python
from cherrypy.lib import auth_digest
USERS = {'jon': 'secret'}
conf = {
'/protected/area': {
'tools.auth_digest.on': True,
'tools.auth_digest.realm': 'localhost',
'tools.auth_digest.get_ha1': auth_digest.get_ha1_dict_plain(USERS),
'tools.auth_digest.key': 'a565c27146791cfb'
}
}
cherrypy.quickstart(myapp, '/', conf)
Favicon
#######
CherryPy serves its own sweet red cherrypy as the default
`favicon <http://en.wikipedia.org/wiki/Favicon>`_ using the static file
tool. You can serve your own favicon as follows:
.. code-block:: python
import cherrypy
class HelloWorld(object):
@cherrypy.expose
def index(self):
return "Hello World!"
if __name__ == '__main__':
cherrypy.quickstart(HelloWorld(), '/',
{
'/favicon.ico':
{
'tools.staticfile.on': True,
'tools.staticfile.filename': '/path/to/myfavicon.ico'
}
}
)
Please refer to the :ref:`static serving <staticontent>` section
for more details.
You can also use a file to configure it:
.. code-block:: ini
[/favicon.ico]
tools.staticfile.on: True
tools.staticfile.filename: "/path/to/myfavicon.ico"
.. code-block:: python
import cherrypy
class HelloWorld(object):
@cherrypy.expose
def index(self):
return "Hello World!"
if __name__ == '__main__':
cherrypy.quickstart(HelloWorld(), '/', app.conf)
|