【发布时间】:2012-06-06 03:02:32
【问题描述】:
我已经在这里查看了所有关于此的问题,查看了瓶子教程,查看了瓶子谷歌小组讨论,并且 AFAIK,我做的一切都是正确的。但是,不知何故,我无法正确加载我的 CSS 文件。我在静态文件上得到 404,找不到 http://localhost:8888/todo/static/style.css,根据下面的目录结构,不应该是这种情况。我正在使用 0.11 版(不稳定)的瓶子;有什么我遗漏的吗,或者这是 Bottle 中的错误?
我的目录结构:
todo/
todo.py
static/
style.css
我的 todo.py:
import sqlite3
from bottle import Bottle, route, run, debug, template, request, validate, static_file, error, SimpleTemplate
# only needed when you run Bottle on mod_wsgi
from bottle import default_app
app = Bottle()
default_app.push(app)
appPath = '/Applications/MAMP/htdocs/todo/'
@app.route('/todo')
def todo_list():
conn = sqlite3.connect(appPath + 'todo.db')
c = conn.cursor()
c.execute("SELECT id, task FROM todo WHERE status LIKE '1';")
result = c.fetchall()
c.close()
output = template(appPath + 'make_table', rows=result, get_url=app.get_url)
return output
@route('/static/:filename#.*#', name='css')
def server_static(filename):
return static_file(filename, root='./static')
我的html:
%#template to generate a HTML table from a list of tuples (or list of lists, or tuple of tuples or ...)
<head>
<link href="{{ get_url('css', filename='style.css') }}" type="text/css" rel="stylesheet" />
</head>
<p>The open items are as follows:</p>
<table border="1">
%for row in rows:
<tr style="margin:15px;">
%i = 0
%for col in row:
%if i == 0:
<td>{{col}}</td>
%else:
<td>{{col}}</td>
%end
%i = i + 1
%end
<td><a href="/todo/edit/{{row[0]}}">Edit</a></td>
</tr>
%end
</table>
【问题讨论】:
-
我也有很多问题。你能在控制台中显示 GET 吗?
-
只需“GET localhost:8888/todo/static/style.css 404(未找到)”
-
你有 todo/todo.py static/style.css。尝试使用 todo/static/style.css。看来您的 dir 结构与 pgm 不匹配。
-
@f p 试试在哪里?我在 html 中尝试了 todo/static/style.css,得到了 todo/static/todo/static/style.css 的 404。
-
磁盘上的文件在哪里?