如何在一个域下放置多个页面?

2024-05-16 04:18:02 发布

您现在位置:Python中文网/ 问答频道 /正文

所以,我有几个应用程序页面,我想把下面的网址像这样

你知道吗常数.heroku.com/physics/planck你知道吗

你知道吗常数.heroku.com/physics/e你知道吗

你知道吗constants.heroku.com/physics/standard重力你知道吗

我的应用程序类型对于普朗克常数应用程序,它是这样的。你知道吗

import os
from flask import Flask

app = Flask('plancksconstant')
app = Flask(__name__.split('.')[0])

@app.route('/physics/planck')
def hello():
    return '6.626068E-34'

if __name__ == '__main__':
    # Bind to PORT if defined, otherwise default to 5000.
    port = int(os.environ.get('PORT', 5000))
    app.run(host='0.0.0.0', port=port)

此应用程序的url是http://nameless-sands-2295.herokuapp.com/physics/planck。我让最后的部分正常工作(/physics/planck),但url的开头仍然是应用程序的名称(nameless-sands-2295)。如何将其更改为“常量”而不是应用程序的名称?你知道吗

解决了!!!! 就这么做了

import os
from flask import Flask

app = Flask('plancksconstant')
app = Flask(__name__.split('.')[0])

@app.route('/physics/planck')
def hello():
    return '6.626068E-34'

@app.route('/physics/standardgravity')
def hello():
    return '9.8'

if __name__ == '__main__':
    # Bind to PORT if defined, otherwise default to 5000.
    port = int(os.environ.get('PORT', 5000))
    app.run(host='0.0.0.0', port=port)

Tags: tonameimportcomapp应用程序flaskheroku
1条回答
网友
1楼 · 发布于 2024-05-16 04:18:02

你将无法将这些设置为使用“常数.heroku.com“-那是heroku.com域,这显然不是您要使用的。不过,你可以建立一个自己的域使用任何域注册(个人,我喜欢)甘地.net但有一百万种选择)。你知道吗

一旦你找到并购买了一个合适的域,你就需要在你的区域文件中建立一个a记录(关于这个的信息太多了,这里是wikipedia:http://en.wikipedia.org/wiki/Zone_file)。将所有请求重定向到,例如“普朗克常数.com“添加到您的heroku应用程序,而不向最终用户显示heroku应用程序url。你知道吗

相关问题 更多 >