问题描述
我有一个简单的烧瓶应用程序,当在笔记本电脑内访问时,该应用程序运行良好。但是,在笔记本电脑外访问时,运行速度较慢。就像手机或同一网络地址或wifi中的其他笔记本电脑一样。
注意,我能够在日志文件中看到正在请求诸如html和css之类的资源。只是那太慢了,以至于我的页面不再加载了。日志文件就是这样。
192.168.100.4 - - [2020-11-08 21:53:00] "GET / HTTP/1.1" 200 1070 0.000000
192.168.100.4 - - [2020-11-08 21:53:00] "GET /static/css/style.css HTTP/1.1" 200 595 0.000000
192.168.100.4 - - [2020-11-08 21:53:00] "GET /static/js/custom.js HTTP/1.1" 200 924 0.000000
所以我要做的是将其包装在gevent自托管服务器中,但问题仍然相同。运行本地主机没有问题。我以为罪魁祸首是Flask开发服务器,但事实并非如此。
from flask import Flask,render_template,jsonify
from gevent.pywsgi import WsgiServer
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
if __name__ == "__main__":
http_server = WsgiServer(('0.0.0.0',8080),app)
http_server.serve_forever()
这些是我的base.html和index.html
<!doctype html>
<html lang="en">
<head>
<!-- required Meta tags -->
<Meta charset="utf-8">
<Meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<link rel="stylesheet" href="{{ url_for('static',filename='css/style.css') }}">
<script src="{{ url_for('static',filename='js/custom.js') }}"></script>
<title>{% block title %} {% endblock %}</title>
</head>
<body>
<nav class="nav" tabindex="-1" onclick="this.focus()">
<div class="container">
<a class="pagename current" href="#">wwww.mypage.com</a>
</div>
</nav>
<button class="btn-close btn btn-sm">×</button>
</nav>
<div class="container">
{% block content %} {% endblock %}
</div>
</body>
</html>
{% extends 'base.html' %}
{% block title %}Welcome to My Page!{% endblock %}
{% block content %}
<div class="container">
<div class="hero">
<h1>Welcome to My Page!</h1>
</div>
</div>
{% endblock %}
注意,我正在Windows笔记本电脑上运行它。我在Bottle中运行的其他应用运行得非常好,但仅使用简单的html时就遇到了Flasks的麻烦。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)