【发布时间】:2014-03-13 07:13:36
【问题描述】:
我在 Raspberry Pi 上的cherrypy 上托管一个测试网页。这是我的python文件代码:
#!/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 内容?
【问题讨论】:
-
听起来你的文件路径不正确。文件请求是否返回 404?您的所有文件都是静态的,包括页面本身吗?那么路径中就不需要“static/”了。
-
此文件与
static文件夹位于同一目录中,因此我假设我必须放置`static` -
尝试删除“static/”。它假定您的文件位于相对于页面的名为 static 的子目录中。
-
即使我拖出 png 文件将 tgt 与 python 文件放在一起,它什么也没给我
-
哦,我想我看错了你的评论
标签: javascript python html css