Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6561837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:38:13+00:00 2026-05-25T13:38:13+00:00

I’m having a devil of a time getting CherryPy to serve the necessary css

  • 0

I’m having a devil of a time getting CherryPy to serve the necessary css file for the page returned.

My directory structure:

Application
     ab.py              (CherryPy application)
     ab.config          (CherryPy config file)
     html\              (html template folder)
        ab.html         (html template file)
     css\               (css folder)
         ab.css         (css file)

The link statement in ab.html:

  <link href="/css/ab.css" rel="stylesheet" type="text/css" />

And finally, ab.config

 [/]
 tools.staticdir.root = "/"

 [/css/ab.css]
 tools.staticfile.on = True
 tools.staticfile.filename = "/css/ab.css"

My template is loaded and rendered to the browser as I expected, but no styling is applied. If I change the template to use a relative address (../css/ab.css) and open the template as a file in the browser, the styling is applied.

It took me a while to get the configuration file to a point where CherryPy did not complain about bad paths when starting the application. At this point it starts, renders, and returns fine but simply doesn’t appear to serve the css file to the browser.

Any help greatly appreciated.

Update based on kind suggestions from fumanchu:

Preferring to use staticdir, and now understanding that the root refers to the filesystem absolute path, I now have this in the config file:

 [/]
 tools.staticdir.root = "c:/users/myaccount/documents/clientname/application"

 [/css]
 tools.staticdir.on = True
 tools.staticdir.dir = "css"

In my HTML I have this style sheet link:

<link href="/css/ab.css" rel="stylesheet" type="text/css" />

And I’m starting CherryPy with this:

 cherrypy.quickstart(ABRoot(), '/', 'ab.config')

In this configuration, I still don’t get styling on my web page. When I check the page source and click on the /css/ab.css link directly, I get

 NotFound: (404, "The path '/css/ab.css' was not found.")

(Note: I’m developing on a windows machine).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:38:13+00:00Added an answer on May 25, 2026 at 1:38 pm

    Change it quickly! The static handlers take paths that are absolute to your filesystem. By setting tools.staticdir.root = "/" you are saying “serve any file from my hard drive”.

    Whew. Now that the panic is over, let’s analyze in more detail. First of all, staticdir and staticfile are different tools, and don’t interact (so you’re only really at risk above if there’s more config you’re not showing us, like tools.staticdir.on = True). If you want to stick with staticfile, you need to provide tools.staticfile.root, not tools.staticdir.root. If you’d rather expose whole directories, then replace staticfile with staticdir throughout.

    Second, let’s fix that .root setting. It should be the path to your “Application” folder (that is, the folder that contains ‘ab.py’ etc).

    Third, the staticdir and staticfile tools determine a disk path with a simple os.path.join(root, dir) (or root, filename), so if you’re supplying a root, your .dir or .filename shouldn’t start with a slash:

    >>> import os
    >>> os.path.join('/path/to/Application', '/css/ab.css')
    '/css/ab.css'
    >>> os.path.join('/path/to/Application', 'css/ab.css')
    '/path/to/Application/css/ab.css'
    

    Given all that, try this config:

    [/]
    tools.staticfile.root = "/path/to/Application"
    
    [/css/ab.css]
    tools.staticfile.on = True
    tools.staticfile.filename = "css/ab.css"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.