Cherrypy Documentation
Total Page:16
File Type:pdf, Size:1020Kb
CherryPy Documentation CherryPy Team Jul 03, 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.......................... 11 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....................................... 16 3.8 Tutorial 8: Make it smoother with Ajax................................. 18 3.9 Tutorial 9: Data is all my life....................................... 21 3.10 Tutorial 10: Make it a modern single-page application with React.js.................. 23 3.11 Tutorial 11: Organize my code...................................... 27 3.12 Tutorial 12: Using pytest and code coverage............................... 28 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.............................................. 43 4.10 Favicon.................................................. 44 5 Advanced 47 5.1 Set aliases to page handlers....................................... 48 5.2 RESTful-style dispatching........................................ 48 5.3 Error handling.............................................. 51 i 5.4 Streaming the response body....................................... 51 5.5 Response timing............................................. 52 5.6 Deal with signals............................................. 53 5.7 Securing your server........................................... 53 5.8 Multiple HTTP servers support..................................... 54 5.9 WSGI support.............................................. 55 5.10 WebSocket support............................................ 56 5.11 Database support............................................. 56 5.12 HTML Templating support........................................ 56 5.13 Testing your application......................................... 56 6 Configure 59 6.1 Architecture............................................... 60 6.2 Declaration................................................ 61 6.3 Namespaces............................................... 63 7 Extend 69 7.1 Server-wide functions.......................................... 70 7.2 Per-request functions........................................... 75 7.3 Tailored dispatchers........................................... 79 7.4 Request body processors......................................... 80 8 Deploy 81 8.1 Run as a daemon............................................. 82 8.2 Run as a different user.......................................... 82 8.3 PID files................................................. 82 8.4 Systemd socket activation........................................ 83 8.5 Control via Supervisord......................................... 83 8.6 SSL support............................................... 84 8.7 WSGI servers............................................... 85 8.8 Virtual Hosting.............................................. 88 8.9 Reverse-proxying............................................. 89 9 Support 93 9.1 I have a question............................................. 93 9.2 I have found a bug............................................ 93 9.3 I have a feature request.......................................... 93 9.4 I want to converse............................................ 94 10 For Enterprise 95 11 Contribute 97 11.1 StackOverflow.............................................. 97 11.2 Filing Bug Reports............................................ 97 11.3 Fixing Bugs............................................... 97 11.4 Writing Pull Requests.......................................... 98 12 Testing 99 13 Glossary 101 14 History 103 14.1 v18.6.1.................................................. 103 14.2 v18.6.0.................................................. 103 14.3 v18.5.0.................................................. 103 ii 14.4 v18.4.0.................................................. 103 14.5 v18.3.0.................................................. 104 14.6 v18.2.0.................................................. 104 14.7 v18.1.2.................................................. 104 14.8 v18.1.1.................................................. 104 14.9 v18.1.0.................................................. 104 14.10 v18.0.1.................................................. 104 14.11 v18.0.0.................................................. 105 14.12 v17.4.2.................................................. 105 14.13 v17.4.1.................................................. 105 14.14 v17.4.0.................................................. 105 14.15 v17.3.0.................................................. 105 14.16 v17.2.0.................................................. 105 14.17 v17.1.0.................................................. 106 14.18 v17.0.0.................................................. 106 14.19 v16.0.3.................................................. 106 14.20 v16.0.2.................................................. 106 14.21 v16.0.0.................................................. 106 14.22 v15.0.0.................................................. 107 14.23 v14.2.0.................................................. 107 14.24 v14.1.0.................................................. 107 14.25 v14.0.1.................................................. 107 14.26 v14.0.0.................................................. 107 14.27 v13.1.0.................................................. 108 14.28 v13.0.1.................................................. 108 14.29 v13.0.0.................................................. 108 14.30 v12.0.2.................................................. 108 14.31 v12.0.1.................................................. 108 14.32 v12.0.0.................................................. 108 14.33 v11.3.0.................................................. 109 14.34 v11.2.0.................................................. 109 14.35 v11.1.0.................................................. 109 14.36 v11.0.0.................................................. 110 14.37 v10.2.2.................................................. 110 14.38 v10.2.1.................................................. 110 14.39 v10.2.0.................................................. 110 14.40 v10.1.1.................................................. 110 14.41 v10.1.0.................................................. 111 14.42 v10.0.0.................................................. 111 14.43 v9.0.0................................................... 111 14.44 v8.9.1................................................... 111 14.45 v8.9.0................................................... 111 14.46 v8.8.0................................................... 112 14.47 v8.7.0................................................... 112 14.48 v8.6.0................................................... 112 14.49 v8.5.0................................................... 112 14.50 v8.4.0................................................... 112 14.51 v8.3.1................................................... 112 14.52 v8.3.0................................................... 113 14.53 v8.2.0................................................... 113 14.54 v8.1.3................................................... 113 14.55 v8.1.2................................................... 113 14.56 v8.1.1................................................... 113 14.57 v8.1.0................................................... 113 iii 14.58 v8.0.1................................................... 114 14.59 v8.0.0................................................... 114 14.60 v7.1.0................................................... 114 14.61 v7.0.0................................................... 114 14.62 v6.2.1................................................... 115 14.63 v6.2.0................................................... 115 14.64 v6.1.1................................................... 115 14.65 v6.1.0................................................... 115 14.66 v6.0.2................................................... 115 14.67 v6.0.1................................................... 115 14.68 v6.0.0................................................... 116 14.69 v5.6.0..................................................