Integrating CSS and CherryPy: How to fix the 404 “/” Not Found Error?

Tags: python,css,http-status-code-404,cherrypy

Problem :

I've been working on testing Twitter Bootstrap with CherryPy 3.2.2, and have reviewed several of the SO posts, but have been unable to successfully get Cherry to run with my configuration files. I'm getting the infamous 404 error: "NotFound: (404, "The path '/' was not found.")".

This is my file setup:

  • /TwitApp (application directory)
    • (my test application)
    • config.conf (configuration file to add CSS)
    • global.conf (global configuration for server socket, port, etc. I think this can go in config.conf?)
    • /css (CSS folder)
      • bootstrap.min.css
    • /js (javascript directory)

This is my code:

    #!/usr/bin/env python
    import cherrypy
    class HelloWorld:
          def index(self):
              return '''<!DOCTYPE html><html><head>
                     <title>Bootstrap Test</title>
                     <meta name="viewport" content="width=device-width, initial-scale=1.0">
                     <!-- Bootstrap -->
                     <link href="../css/bootstrap.min.css" rel="stylesheet" media="screen">
                     <h1>Bootstrap Test</h1>
                     <button type="button" class="btn">Submit</button>
 = True

    #I tried this example that I found in the documentation and on previous posts with the same 404 result:
    #cherrypy.quickstart(HelloWorld(), "/", "config.conf")

    #I tried this one when I reviewed another post on here:

At one point the [global] section of my global.conf file was the top section of my config.conf file, but I split the two up when I started using the mount, start and block methods.

Here is my global.conf file:

    server.socket_host = ""
    server.socket_port = 8080
    log.screen: True
    log.error_file: "/Users/myUser/tmp/newproject/cherrypy.error"
    log.access_file: "/Users/myUser/tmp/newproject/cherrypy.access"

Here is my config.conf file:

    tools.staticfile.root = "/Users/myUser/tmp/newproject/TwitApp"

    tools.staticfile.on = True
    tools.staticfile.filename = "css/bootstrap.min.css"

This is the full error message: 404 Not Found

    The path '/' was not found.

    Traceback (most recent call last):
      File "/Library/Python/2.7/site-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/", line 656, in respond
        response.body = self.handler()
      File "/Library/Python/2.7/site-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/lib/", line 188, in __call__
        self.body = self.oldhandler(*args, **kwargs)
       File "/Library/Python/2.7/site-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/", line 386, in __call__
        raise self
       NotFound: (404, "The path '/' was not found.")

The articles I read through the most can be found here: Cherrypy returning NotFound: (404, "The path '/' was not found.") and here: Path Not Found in CherryPy. Can someone please advise what I'm doing incorrectly?

Solution :

Final answer: I decided that I should just start troubleshooting, so I hacked down all of the CherryPy configurations and just did a basic cherrypy.quickstart(HelloWorld()) with the template I had. I was still getting the 404 error, so that meant that there was something fundamentally wrong with my code, not a config error. I kept looking through everything and then I found it. On vim, my code alignment was a little off and that's when I noticed that = True was not set outside the index function! D'oh! I replaced it and now it's working with CSS, so anyone who's interested in learning how to implement CherryPy with CSS, there ya go!

    CSS Howto..

    How to resolve css incompabilities/differences between different versions of IE?

    How should I use `position` and other properties correctly to position my web page?

    .addClass - How to call CSS from linked css?

    How to apply custom CSS and Javascript specific CMS page Magento

    How to create a multiple columns with HTML CSS

    How to set borders between children from parent in CSS?

    CSS How to force DIVs side by side with text overflow?

    How to design multiple time clock wise rotation of a image in css

    How do I create page transitions for my website

    CSS Selector-How to locate Parent Element

    How to apply css transform on iOS without using -webkit-transform?

    how to indent HTML forms on modals [closed]

    show loading div with overlay on submit while waiting

    How to fix float sidebar in Wordpress with Constructor theme?

    How can one select a parent element several levels above the child element utilizing the 'hover' selector and ':has()'?

    How do you create multiple box-shadow values in LESS CSS

    How to create a horizontal scroll bar when shrinking the window

    How to put a space in front of a next line [closed]

    What's the difference between “.” and “#” in CSS and how to choose to use?

    ASP.Net MVC: How can I easily change the tab color of my navigation menu based on the tab that I'm on?

    How can I add a consistent left margin to a checkbox label?

    How to write CSS selector for this page?

    How can i apply background-image to low div

    How to modify CSS when requirements change?

    How to center text horizontally & vertically within dotted border

    How to use SASS logic within a CSS 3 media query [duplicate]

    How to set CSS rule for a DIV in a LI of class UL?

    How to center align

    How do I make a nested
    expand to its contents?

    How to move some text down in a li tag?