我在哪里定义由Flask中的url_for()使用的域? [英] Where do I define the domain to be used by url_for() in Flask?
本文介绍了我在哪里定义由Flask中的url_for()使用的域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我调用 url_for('index')
时,它会生成'/'
'喜欢它生成'domain.tld /'
来代替。我无法在文档中找到我要指定的地方。我只需要做'domain.tld /%s'%url_for('index')
?
When I call url_for('index')
it will generate '/'
but there are times where I'd like it to generate 'domain.tld/'
instead. I can't find in the documentation where I would specify this. Do I just need to do 'domain.tld/%s' % url_for('index')
?
推荐答案
url_for
需要一个 _external
关键字参数,它将返回绝对(而不是相对)的URL。我相信你需要在你的根域设置 SERVER_NAME
config密钥才能正常工作。
url_for
takes an _external
keyword argument that will return an absolute (rather than relative) URL. I believe you will need to set a SERVER_NAME
config key with your root domain to make it work correctly.
这篇关于我在哪里定义由Flask中的url_for()使用的域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文