WebFaction
Community site: login faq

I'm trying to serve my cherrypy application a css file but something isn't working. I get no error message but my formatting from the css file are not being implemented. I've got my cherrpy app in

home/webapps/spotipy

and my css file in

home/webapps/spotipy/css

At the top of my python code I've got

#!/usr/local/bin/python3.2
import cherrypy
import os.path

current_dir = os.path.dirname(os.path.abspath(__file__))

class Root(object):
    @cherrypy.expose
    def index(self):

            return '''<html> 
                      <head>
                        <title>Spoti.py</title>
                        <link rel="stylesheet" href="css/my_css.css" type="text/css" />
                      </head>
                      <p> hi </p>

                      <body>
                      <p> hi joey </p>
            %s
            </body></html>''' %text

And this at the bottom

if __name__ == "__main__":

    cherrypy.quickstart(Root(), '/', config={

        '/css':
        { 'tools.staticdir.on':True,
          'tools.staticdir.dir':os.path.join(current_dir,"/css")
        },
        '/my_css.css':
        { 'tools.staticfile.on':True,
          'tools.staticfile.filename':os.path.join(current_dir,"/my_css.css")
        }

    })

asked 16 Sep '13, 03:46

joestox
3613
accept rate: 0%

edited 16 Sep '13, 04:20

It looks like your directories are set up incorrectly. The path should be the absolute path, such as "/home/myusername/webapps/spotipy/css" (note your missing forward slash at the start).

(16 Sep '13, 03:58) waynek

I believe CherryPy interprets that path (/my_css.css) as an absolute path, so you just need to fix the path to include the whole path to your css file, and it should work.

permanent link

answered 16 Sep '13, 07:03

Zamphatta
315
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×337
×125
×32
×12

question asked: 16 Sep '13, 03:46

question was seen: 3,797 times

last updated: 16 Sep '13, 07:03

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM