【发布时间】:2017-01-01 10:14:13
【问题描述】:
我正在尝试制作一个小的生物信息学网络应用程序。我让它与 CGI 一起工作,我正在尝试调整它,以便我可以在 pythonanywhere 或 heroku 上提供它。
我遇到的问题是样式表和 javascript 没有加载。我对编程很陌生,但在发布之前我已经进行了广泛的搜索。我从应用程序中删除了很多内容以隔离问题。应用程序的目录现在看起来像:
/app
main.html
main.css
main.js
WSGI_app.py
WSGI_app.py 中的代码如下:
from wsgiref.simple_server import make_server
import jinja2
def application( environ, start_response ):
templateLoader = jinja2.FileSystemLoader( searchpath="./" )
env = jinja2.Environment( loader=templateLoader )
template = env.get_template( 'main.html' )
template = template.render()
start_response("200 OK", [( "Content-Type", "text/html" )])
yield(template.encode( "utf8" ))
httpd = make_server('localhost', 8051, application)
httpd.serve_forever()
main.html 的顶部看起来像:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Chimera Quest</title>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="./main.css" />
<script type="text/javascript" src="./main.js"></script>
</head>
我尝试将“./main.css”替换为“/main.css”和“main.css”。
我的浏览器控制台显示:
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:8051/main.css".
有人在这里看到什么吗?我完全没有想法。
【问题讨论】:
标签: python html css jinja2 wsgi