我已经在这里查看了所有关于此的问题,查看了瓶子教程,查看了瓶子谷歌小组讨论,以及 AFAIK,我做的一切都是正确的。但是,不知何故,我无法正确加载我的 CSS 文件。我在静态文件上得到一个 404,http://localhost:8888/todo/static/style.css
没有找到,根据下面的目录结构,不应该是这种情况。我正在使用 0.11 版(不稳定)的瓶子;有什么我遗漏的吗,或者这是瓶子中的错误?
我的目录结构:
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>