2014-03-13 94 views
2

我在Raspberry Pi上的cherrypy上托管测试网页。这里是我的代码python文件:网页无法显示我的css

#!/usr/bin/python 

import cherrypy 

class Control: 

    @cherrypy.expose 
    def index(self): 
     return '''<!DOCTYPE html> 
     <html> 
      <head> 
       <title>RaspiCare</title> 

       <meta name="viewport" content="width=device-width, initial-scale=1"> 

       <link rel="stylesheet" href="static/jquery.mobile-1.4.0.min.css"> 
       <link rel="stylesheet" href="static/style.css"> 
       <script src="static/jquery-1.10.2.min.js"></script> 
       <script src="static/jquery.mobile-1.4.0.min.js"></script> 


      </head> 
      <body style="overflow: scroll;overflow-x:hidden;"> 
          <div data-role="page" data-theme="a" id="page1"> 

       <div data-role="header"> 
        <img src="static/raspicare_logo.png"> 

       </div><!-- /header --> 

       </div> 

      </body> 
     </html> 
       ''' 
    @cherrypy.expose 
    def turnCamera (**data): 

      import pigpio 
      import time 

      # import serial 
      # def servo_control(command): 
      # serialport= serial.Serial ("/dev/ttyACM0", 9600, timeout=0.5) 
      # serialport.write(command) 
      # return serialport.readlines(1) 

      servos=4 
      key = data['direction'] 
      if key=="left": 
        servostatus = "left" 
        print servostatus 
        m=1500 
      else: 
        m=1000 

    ## m=1500 
    ## while (m >= 500 and m <= 2500): 
    ##  if (key =="left"): 
    ##   print "left" 
    ##   m=m+100 
    ##  elif (key =="right"): 
    ##   m=m-100 

      pigpio.start() 

      pigpio.set_servo_pulsewidth(servos, m) 
      servostat= "Servo {} {} {} micro pulses".format(servos[0], key, m) 
      print servostat 
      time.sleep(1) 

      pigpio.stop() 

      return servostat 


    #shutdown server 
    @cherrypy.expose 
    def shutdown(self): 
     cherrypy.engine.exit() 

import os.path 
tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf') 

if __name__ == '__main__': 
    # CherryPy always starts with app.root when trying to map request URIs 
    # to objects, so we need to mount a request handler root. A request 
    # to '/' will be mapped to Comfort().index(). 
    cherrypy.quickstart(Control(), config=tutconf) 
else: 
    # This branch is for the test suite; you can ignore it. 
    cherrypy.tree.mount(Control(), config=tutconf) 

我已经删除了大部分html内容,并试图只显示标题徽标。我拥有我的static文件夹中的所有内容,并且我非常确定那些css文件可以在其他页面上使用。但为什么页面不显示徽标或任何CSS内容?

+0

这听起来像你的文件路径不正确。对文件的请求是否返回404?所有的文件都是静态的,包括页面本身?那么你不需要路径中的“静态/”。 – Mathias

+0

这个文件和'static'文件夹在同一个目录下,所以我假设我必须把'static \' – yvonnezoe

+0

尝试并移除“static /”。它假定你的文件在一个名为static的子目录中,相对于页面。 – Mathias

回答

1

解决

这与CherryPy的配置文件做。 tutorial.conf必须修改如下:

[global] 
server.socket_host = "0.0.0.0" 
server.socket_port = 8080 
server.thread_pool = 10 
[/] 
tools.staticdir.root = "/directory to the static folder" 
[/static] 
tools.staticdir.on = True 
tools.staticdir.dir = "static"