我在哪里定义 url_for() 在 Flask 中使用的域? [英] Where do I define the domain to be used by url_for() in Flask?
本文介绍了我在哪里定义 url_for() 在 Flask 中使用的域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我调用 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
配置键才能使其正常工作.
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.
这篇关于我在哪里定义 url_for() 在 Flask 中使用的域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文