Creating a local custom host name instead of localhost?

淺唱寂寞╮ 提交于 2019-12-21 17:19:21

问题


Currently, my flask app runs locally on:

http://localhost:5000/some_page

How could I create a local custom location for my app like:

http://myappname/some_page

Sort of like a local domain name. Is this possible at all? Any pointers would be great.


回答1:


In order for the browser to resolve this custom name, you will need to add an alias to your /etc/hosts file. It probably already contains a line about 127.0.0.1, in which case you just add your alias to the list

127.0.0.1 localhost localhost.localdomain myappname

You can then change the server name in the app's config to make it explicitly use this name.

app.config['SERVER_NAME'] = 'myappname:5000'

Only privileged programs (run as root or with sudo) can bind to low ports such as 80, so you will still have to use a high port number.




回答2:


It can be done using SERVER_NAME option in config:

app = Flask(__name__)
app.config['SERVER_NAME'] = 'myappname:80'

More information here: http://flask.pocoo.org/docs/0.10/config/



来源:https://stackoverflow.com/questions/28288254/creating-a-local-custom-host-name-instead-of-localhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!