所以我正在研究这个项目,我正在使用Flask,而且我还是使用Flask的新手。但是,每当我尝试运行我用于此项目的脚本时,我都会收到一个抱怨app.run()的追踪调用。
这是我脚本中的代码:
import os
from flask import Flask, render_template, request, flash, redirect, url_for
from flask.ext.assets import Environment, Bundle
from flask_wtf import Form
from wtforms import TextField, TextAreaField, SubmitField
from wtforms.validators import InputRequired
CSRF_ENABLED = True
app = Flask(__name__)
app.secret_key = 'development key'
assets = Environment(app)
assets.url = app.static_url_path
scss = Bundle('assets/scss/app.scss', filters='scss', output='css/app.css')
assets.register('app_scss', scss)
@app.route('/')
def server_1():
return render_template('server_1.html')
if __name__ == '__main__':
app.run()
这是脚本保持输出的回溯(我将各个回溯分开以使它们更容易阅读):
$python app.py
* Running on http://127.0.0.1:5000/
Traceback (most recent call last):
File "app.py", line 22, in <module>
app.run()
File "/Library/Python/2.7/site-packages/flask/app.py", line 772, in run
run_simple(host, port, self, **options)
File "/Library/Python/2.7/site-packages/Werkzeug-0.9.6- py2.7.egg/werkzeug/serving.py", line 710, in run_simple
inner()
File "/Library/Python/2.7/site-packages/Werkzeug-0.9.6-py2.7.egg/werkzeug/serving.py", line 692, in inner
passthrough_errors, ssl_context).serve_forever()
File "/Library/Python/2.7/site-packages/Werkzeug-0.9.6-py2.7.egg/werkzeug/serving.py", line 486, in make_server
passthrough_errors, ssl_context)
File "/Library/Python/2.7/site-packages/Werkzeug-0.9.6-py2.7.egg/werkzeug/serving.py", line 410, in __init__
HTTPServer.__init__(self, (host, int(port)), handler)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 419, in __init__
self.server_bind()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py", line 108, in server_bind
SocketServer.TCPServer.server_bind(self)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 430, in server_bind
self.socket.bind(self.server_address)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 48] Address already in use
我不太确定我做错了什么,所以我们非常感谢能给予的任何帮助。
答案 0 :(得分:2)
最后的错误:
socket.error: [Errno 48] Address already in use
表示您已经在127.0.0.1端口5000上运行了其他东西。
要找出使用此地址的进程,可以运行以下命令(在OS X上)
lsof -i tcp:5000
或者,如果您希望使用其他端口,例如5001,请调整您的代码:
if __name__ == '__main__':
app.run(port=5001)