Cherrypy Documentation
Total Page:16
File Type:pdf, Size:1020Kb
CherryPy Documentation CherryPy Team Jan 17, 2021 CONTENTS 1 Foreword 1 1.1 Why CherryPy?.............................................1 1.2 Success Stories..............................................2 2 Installation 5 2.1 Requirements...............................................5 2.2 Supported python version........................................6 2.3 Installing.................................................6 2.4 Run it...................................................6 3 Tutorials 9 3.1 Tutorial 1: A basic web application................................... 10 3.2 Tutorial 2: Different URLs lead to different functions.......................... 10 3.3 Tutorial 3: My URLs have parameters.................................. 11 3.4 Tutorial 4: Submit this form....................................... 12 3.5 Tutorial 5: Track my end-user’s activity................................. 13 3.6 Tutorial 6: What about my javascripts, CSS and images?........................ 14 3.7 Tutorial 7: Give us a REST....................................... 15 3.8 Tutorial 8: Make it smoother with Ajax................................. 17 3.9 Tutorial 9: Data is all my life...................................... 20 3.10 Tutorial 10: Make it a modern single-page application with React.js.................. 23 3.11 Tutorial 11: Organize my code...................................... 26 3.12 Tutorial 12: Using pytest and code coverage.............................. 27 4 Basics 31 4.1 The one-minute application example.................................. 32 4.2 Hosting one or more applications.................................... 33 4.3 Logging.................................................. 34 4.4 Configuring................................................ 37 4.5 Cookies.................................................. 38 4.6 Using sessions.............................................. 39 4.7 Static content serving.......................................... 40 4.8 Dealing with JSON............................................ 42 4.9 Authentication.............................................. 42 4.10 Favicon.................................................. 44 5 Advanced 45 5.1 Set aliases to page handlers....................................... 46 5.2 RESTful-style dispatching........................................ 46 5.3 Error handling.............................................. 49 i 5.4 Streaming the response body....................................... 49 5.5 Response timing............................................. 50 5.6 Deal with signals............................................. 51 5.7 Securing your server........................................... 51 5.8 Multiple HTTP servers support..................................... 52 5.9 WSGI support.............................................. 52 5.10 WebSocket support............................................ 54 5.11 Database support............................................. 54 5.12 HTML Templating support........................................ 54 5.13 Testing your application......................................... 54 6 Configure 57 6.1 Architecture............................................... 58 6.2 Declaration................................................ 59 6.3 Namespaces............................................... 61 7 Extend 67 7.1 Server-wide functions.......................................... 68 7.2 Per-request functions........................................... 73 7.3 Tailored dispatchers........................................... 77 7.4 Request body processors......................................... 78 8 Deploy 79 8.1 Run as a daemon............................................. 80 8.2 Run as a different user.......................................... 80 8.3 PID files................................................. 80 8.4 Systemd socket activation........................................ 81 8.5 Control via Supervisord......................................... 81 8.6 SSL support............................................... 82 8.7 WSGI servers............................................... 83 8.8 Virtual Hosting.............................................. 86 8.9 Reverse-proxying............................................. 87 9 Support 89 9.1 I have a question............................................. 89 9.2 I have found a bug............................................ 89 9.3 I have a feature request.......................................... 89 9.4 I want to converse............................................ 90 10 For Enterprise 91 11 Contribute 93 11.1 StackOverflow.............................................. 93 11.2 Filing Bug Reports............................................ 93 11.3 Fixing Bugs............................................... 93 11.4 Writing Pull Requests.......................................... 94 12 Testing 95 13 Glossary 97 14 History 99 14.1 v18.6.1.................................................. 99 14.2 v18.6.0.................................................. 99 14.3 v18.5.0.................................................. 99 ii 14.4 v18.4.0.................................................. 99 14.5 v18.3.0.................................................. 100 14.6 v18.2.0.................................................. 100 14.7 v18.1.2.................................................. 100 14.8 v18.1.1.................................................. 100 14.9 v18.1.0.................................................. 100 14.10 v18.0.1.................................................. 100 14.11 v18.0.0.................................................. 101 14.12 v17.4.2.................................................. 101 14.13 v17.4.1.................................................. 101 14.14 v17.4.0.................................................. 101 14.15 v17.3.0.................................................. 101 14.16 v17.2.0.................................................. 101 14.17 v17.1.0.................................................. 102 14.18 v17.0.0.................................................. 102 14.19 v16.0.3.................................................. 102 14.20 v16.0.2.................................................. 102 14.21 v16.0.0.................................................. 102 14.22 v15.0.0.................................................. 103 14.23 v14.2.0.................................................. 103 14.24 v14.1.0.................................................. 103 14.25 v14.0.1.................................................. 103 14.26 v14.0.0.................................................. 103 14.27 v13.1.0.................................................. 104 14.28 v13.0.1.................................................. 104 14.29 v13.0.0.................................................. 104 14.30 v12.0.2.................................................. 104 14.31 v12.0.1.................................................. 104 14.32 v12.0.0.................................................. 104 14.33 v11.3.0.................................................. 105 14.34 v11.2.0.................................................. 105 14.35 v11.1.0.................................................. 105 14.36 v11.0.0.................................................. 106 14.37 v10.2.2.................................................. 106 14.38 v10.2.1.................................................. 106 14.39 v10.2.0.................................................. 106 14.40 v10.1.1.................................................. 106 14.41 v10.1.0.................................................. 107 14.42 v10.0.0.................................................. 107 14.43 v9.0.0................................................... 107 14.44 v8.9.1................................................... 107 14.45 v8.9.0................................................... 107 14.46 v8.8.0................................................... 108 14.47 v8.7.0................................................... 108 14.48 v8.6.0................................................... 108 14.49 v8.5.0................................................... 108 14.50 v8.4.0................................................... 108 14.51 v8.3.1................................................... 108 14.52 v8.3.0................................................... 109 14.53 v8.2.0................................................... 109 14.54 v8.1.3................................................... 109 14.55 v8.1.2................................................... 109 14.56 v8.1.1................................................... 109 14.57 v8.1.0................................................... 109 iii 14.58 v8.0.1................................................... 110 14.59 v8.0.0................................................... 110 14.60 v7.1.0................................................... 110 14.61 v7.0.0................................................... 110 14.62 v6.2.1................................................... 111 14.63 v6.2.0................................................... 111 14.64 v6.1.1................................................... 111 14.65 v6.1.0................................................... 111 14.66 v6.0.2................................................... 111 14.67 v6.0.1................................................... 111 14.68 v6.0.0................................................... 112 14.69 v5.6.0................................................... 112 14.70 v5.5.0..................................................