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)
    • testPy.py (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 testPy.py 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">
                     </head><body>
                     <h1>Bootstrap Test</h1>
                     <button type="button" class="btn">Submit</button>
                     </body></html>'''
          index.exposed = 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:
    cherrypy.config.update("global.conf")
    cherrypy.tree.mount(HelloWorld(),"/","config.conf")
    cherrypy.engine.start()
    cherrypy.engine.block()

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:

    [global]
    server.socket_host = "127.0.0.1"
    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"

    [/css/bootstrap.min.css]
    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/_cprequest.py", line 656, in respond
        response.body = self.handler()
      File "/Library/Python/2.7/site-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/lib/encoding.py", 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/_cperror.py", 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 index.exposed = 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 do I highlight only the innermost table row of a nested table?

    How to create rolldown content with css?

    CSS - How to only apply a style to a div that is inside another div?

    How to create spaces between elements in HTML/CSS

    How to format an HTML table using CSS for printing?

    How to horizontally center align a span inside a div

    How to move one element to the right of another using CSS?

    How do I show just one image and center it in a slider?

    How to center a IMG tag horizontaly and vertically using html and css in ie7?

    How to get anchor tag on background image of div?

    how to bypass style in element that is automatically applied through class?

    jQuery - How to get all styles/css (defined within internal/external document) with HTML of an element

    How to save css style after hover action

    How do I tell what are the ids and classes of a rail html.erb component?

    How to get 2 fixed and 1 dynamic column in CSS

    How to use a background image in Webfolio WordPress theme without breaking CSS header?

    DOM How to add two divs (with jQuery inside them) next to each other?

    How to check if all CSS files have been downloaded to insert HTML using JavaScript?

    Base 64 CSS background image not showing in IE

    How to design this html Box for legacy browsers

    How to make a progress bar

    how do I prevent max-height transition from scrolling the page to the top?

    How to stop shadow effect from moving using pure css?

    How to set background-image to take remaining section of the page in semantic-ui

    CSS - How to display dropdown text in one row?

    asp.net mvc view css not showing as expected

    Dialogs are showing at the bottom of the page

    CSS How to use margins with different divs

    How to set the background image width using CSS?

    How to add multiple button in 1 line (css)? [duplicate]