【发布时间】:2012-05-16 04:55:50
【问题描述】:
我已经尝试阅读 Bottle 的文档,但是,我仍然不确定静态文件服务的工作原理。我有一个index.tpl 文件,其中有一个附加的css文件,它可以工作。但是,我读到 Bottle 不会自动提供 css 文件,如果页面加载正确,这是不可能的。
但是,我在请求页面时遇到了速度问题。那是因为我没有使用return static_file(params go here)吗?如果有人能弄清楚它们是如何工作的,以及在加载页面时如何使用它们,那就太好了。
服务器代码:
from Bottle import route,run,template,request,static_file
@route('/')
def home():
return template('Templates/index',name=request.environ.get('REMOTE_ADDR'))
run(host='Work-PC',port=9999,debug=True)
索引:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type"
content="text/html; charset=ISO-8859-1">
<title>index</title>
<link type="text/css"
href="cssfiles/mainpagecss.css"
rel="stylesheet">
</head>
<body>
<table
style="width: 100%; text-align: left; margin-left: auto; margin-right: auto;"
border="0" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td>
<h1><span class="headertext">
<center>Network
Website</center>
</span></h1>
</td>
</tr>
</tbody>
</table>
%if name!='none':
<p align="right">signed in as: {{name}}</p>
%else:
pass
%end
<br>
<table style="text-align: left; width: 100%;" border="0" cellpadding="2"
cellspacing="2">
<tbody>
<tr>
<td>
<table style="text-align: left; width: 100%;" border="0"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="width: 15%; vertical-align: top;">
<table style="text-align: left; width: 100%;" border="1"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td>Home<br>
<span class="important">Teamspeak Download</span><br>
<span class="important">Teamspeak Information</span></td>
</tr>
</tbody>
</table>
</td>
<td style="vertical-align: top;">
<table style="text-align: left; width: 100%;" border="1"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td>
<h1><span style="font-weight: bold;">Network Website</span></h1>
To find all of the needed information relating to the network's social
capabilities, please refer to the links in the side bar.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>
【问题讨论】:
-
我对bottle了解不多,但是说它不提供静态文件的说法可能仅适用于生产模式,不适用于开发。让您的 Apache 或您正在使用的任何东西提供静态文件通常会更有效。顺便说一句......你的 HTML 中有太多的表格;)
标签: python python-2.7 bottle