概括
一天,我在用我的linux调试网页时,我忽然遇到了这样一个报错
代码:
import flask
app = flask.Flask(__name__)
@app.route('/',subdomain='123')
def home_123():
return 'hello world'
app.config['SERVER_NAME'] = 'test.com:5000'
app.run()
报错:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/***马赛克***/anaconda3/lib/python3.7/site-packages/flask/app.py", line 943, in run
run_simple(host, port, self, **options)
File "/Users/***马赛克***/anaconda3/lib/python3.7/site-packages/werkzeug/serving.py", line 814, in run_simple
inner()
File "/Users/***马赛克***/anaconda3/lib/python3.7/site-packages/werkzeug/serving.py", line 774, in inner
fd=fd)
File "/Users/***马赛克***/anaconda3/lib/python3.7/site-packages/werkzeug/serving.py", line 660, in make_server
passthrough_errors, ssl_context, fd=fd)
File "/Users/***马赛克***/anaconda3/lib/python3.7/site-packages/werkzeug/serving.py", line 577, in __init__
self.address_family), handler)
File "/Users/***马赛克***/anaconda3/lib/python3.7/socketserver.py", line 452, in __init__
self.server_bind()
File "/Users/***马赛克***/anaconda3/lib/python3.7/http/server.py", line 137, in server_bind
socketserver.TCPServer.server_bind(self)
File "/Users/***马赛克***/anaconda3/lib/python3.7/socketserver.py", line 466, in server_bind
self.socket.bind(self.server_address)
OSError: [Errno 49] Can't assign requested address
经过一番百度,原来是我的SERVER_NAME是test.com:5000
,但是我并没有给localhost
配上test.com:5000
的域名。
哦,对了,我还得配上123.test.com:5000
的域名。
开始
首先,配置域名就需要修改"/etc/hosts"
执行命令:
sudo vim /etc/hosts
出现一下场景后输入密码(有可能不出现)
输入完成后出现以下场景:
按需求添加,格式:
127.0.0.1 <将此处替换成你需要的>
例如我需要添加的:
127.0.0.1 test.com
127.0.0.1 123.test.com
结果:
到此,就完成了
作者
hit-road
拜拜,下课!
hit-road不定期跟新,不见不散!