- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我是 Python 和一般编程的新手。我使用名为 Tornado 的 Web 服务器来“托管”我的网站。每当我使用 self.render("example.html", variables here) 生成动态 html 页面时,生成的 html 页面没有合并 CSS,因为它只是生成 html 页面即使我将 .css 文件与 example.html 页面放在同一文件夹“Tornado/template”中,也没有 CSS 改善其外观。很确定我也正确地获得了 html 到 css 标签的链接。
如果我使用浏览器而不是 Tornado 打开 example.html,它将使用 .css 文件“呈现”。
因为我不知道为什么会这样,我就把我所有的代码贴在这里:这是 Tornado 中的 app.py:
import config
import os.path
import re
import MySQLdb
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render("question3.html")
class StopTornado(tornado.web.RequestHandler):
def get(self):
tornado.ioloop.IOLoop.instance().stop()
class ReturnQuery(tornado.web.RequestHandler):
def post(self):
connection = MySQLdb.connect(**config.mysql_config)
cursor = connection.cursor()
if 'lowermass' in self.request.arguments and 'uppermass' in self.request.arguments:
lowermass = self.get_argument('lowermass')
uppermass = self.get_argument('uppermass')
# Testing for bad input and should block Injection attacks
# Since you can't really do an injection attack with only numbers
# Placing any non-int input will throw an exception and kick you to the Error.html page
try:
lowermass = int(lowermass)
uppermass = int(uppermass)
except ValueError:
self.render("Error.html")
if lowermass < uppermass:
cursor.execute ('''SET @row_num=0;''')
cursor.execute('''SELECT @row_num:=@row_num+1 as 'Num', b.commonname
FROM Bird b
JOIN Bodymass m ON b.EOLid = m.EOLid
WHERE m.mass BETWEEN %s AND %s
GROUP BY b.commonname''',(lowermass, uppermass))
birds = cursor.fetchall()
self.render("question2.html", birds = birds)
else:
self.render("Error.html")
else :
self.render("Error.html")
class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r"/", MainHandler),
# Add more paths here
(r"/KillTornado/", StopTornado),
(r"/tables/", ReturnQuery),
(r"/tables/localhost8888", MainHandler)
]
settings = {
"debug": True,
"template_path": os.path.join(config.base_dir, "templates"),
"static_path": os.path.join(config.base_dir, "static")
}
tornado.web.Application.__init__(self, handlers, **settings)
if __name__ == "__main__":
app = Application()
app.listen(config.port)
print "Starting tornado server on port %d" % (config.port)
tornado.ioloop.IOLoop.instance().start()
这是我要呈现的 html 页面:
所以基本上,我从网络用户的不同 html 页面接收到两个整数输入,并且在数据库上执行上面的 app.py 的 mysql 查询。它返回所有结果的列表(我认为它是列表的列表),我使用数据填写下面 html 页面中的表格,但它是包含不会用 css“呈现”的表格的 html 页面.
lowermass 和 uppermass 是用户输入(必须是整数)。 question3.html 是获取用户输入的 html 页面,而 question2.html 是带有表格的 html 页面。
我真的希望这只是一个我可以快速修复的愚蠢错误。
<html>
<head>
<link rel = "stylesheet" type ="text/css" href = "presnt.css">
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function(){
$('#table').dataTable();
});
</script>
<title>Birds with body mass in range</title>
<div id = "header">
Birds with body mass in range
</div>
<br>
</head>
<body>
<table id = "table">
<thead>
<tr>
<td style="padding:4px;border-top:1px solid black;">rownum</td>
<td style="padding:4px;border-top:1px solid black;">common name</td>
</tr>
<tr>
<td style = "padding:1px;border-top:1px solid black;">
</td>
<td style = "padding:1px;border-top:1px solid black;">
</td>
</tr>
</thead>
<tbody>
{% if birds %}
{% for bird in birds %}
<tr>
<td>{{ bird[0] }} </td>
<td>{{ bird[1] }}</td>
</tr>
{% end %}
{% else %}
<tr>
<td colspan = 2> No results returned</td>
</tr>
{% end %}
</tbody>
</table>
</body>
最佳答案
it just generates the html page with no CSS improving its appearance even though I've placed my .css file along with the example.html page in the same folder "Tornado/template". Pretty sure I got that link html to css tag right as well.
css 属于静态文件夹,您已在此处声明:
"static_path": os.path.join(config.base_dir, "static")
这是将它链接到模板中的方法:
<link rel="stylesheet" href="{{ static_url("presnt.css") }}">
关于python - Tornado/Python self.render ("example.html") 忽略 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23988185/
根据一些谷歌搜索,我安装了以下错误处理程序。然而,似乎返回 http 500 的 python 异常并没有被这些东西捕获,尽管 404 是这样。通过我在下面的代码中留下的打印语句,我可以看到它没有命中
我刚刚意识到 WebSocketHandler.write_message() 返回一个 Future。我以前没有在我的函数中产生过这个函数: @tornado.gen.coroutine
这是我的 Tornado 文件:: from tornado.wsgi import WSGIContainer from tornado.ioloop import IOLoop from torn
class MainHandler(BaseHandler): @tornado.web.authenticated def get(self): self.rende
我正在尝试使用 AsyncHTTPTestCase 测试 Tornado .我想测试标有 @tornado.web.authenticated 注释的处理程序。因为此处理程序需要身份验证,所以我们必须
我正在使用 Tornado Web Server (版本 4.1)使用 Python 2.7 创建 REST Web 应用程序。我的请求处理程序之一 (web.RequestHandler) 使用多部
我想知道tornado 的内部工作流程,并且看过this article ,很好,但我就是想不通 ioloop.py里面有这样一个函数 def add_handler(self, fd, handle
如何遍历从 Python/Tornado 处理程序传递到 Tornado 模板的字典? 我试过 {% for key, value in statistics %}
我有一个 Tornado 后端,为 Angular 前端提供服务。更新数据库时,tornado api 不会获取更新的数据。它仅在我重新启动服务器后出现。有人可以帮我解决这个问题吗?我希望获取的数据能
我尝试使用自定义的 WSGIContainer 来处理异步操作: from tornado import httpserver, httpclient, ioloop, wsgi, gen @gen.
from tornado.web import RequestHandler class HelloWorldHandler(RequestHandler): def get(self):
Pylint 遇到 @tornado.web.authenticated 时崩溃 class Handler1(tornado.web.RequestHandler): def get(sel
经过 tornado.gen documentation有人可以帮我理解 tornado.gen.coroutine 和 tornado.gen.engine 之间的确切区别 最佳答案 正如 gen.
代码如下: from tornadoredis import Client from tornado.ioloop import IOLoop from tornado.gen import coro
我有一个 tornado.websocket.WebSocketHandler 的子类。在该类中,我有一个方法使用 Django ORM 从子类模型中获取用户:django.contrib.auth.
我是 ssl 之类的新手,我已经使用 openssl 生成了自签名证书。 openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days
我已经从 tornado 4.2 移动到 tornado 6.0.3,我得到了错误 AttributeError:模块“tornado.web”没有属性“异步” 根据 tornado v6 seems
我一直在关注此 ( https://developer.ibm.com/tutorials/se-distributed-apps-zeromq-part2/) 教程,以设置使用 CurveZMQ 加
我在使用tornado-celery整合tornado和celery时,出现错误:``` traceback (most recent call last): File "/usr/local/l
我正在使用 Tornado 与 twitter 等第三方进行身份验证。 我的登录处理程序看起来像这样 class AuthLoginHandler(BaseHandler, tornado.auth.
我是一名优秀的程序员,十分优秀!