0
我正在使用url_for和Python Flask發生錯誤。錯誤如下: MissingSchema: Invalid URL
url_for url_for無效的網址
不知道是什麼問題。這裏是我的代碼:
@app.route("/", methods=('GET', 'POST'))
def landing():
form = forms.OptinForm()
if form.validate_on_submit():
requests.get(url_for('indoctrination', email=form.email.data, name=form.first_name.data))
return render_template('index.html', form=form)
這是正確的答案,但'url_for'也可以使用'_external'關鍵字arg爲'url_for('indoctrination',...,_external = True)'生成完整的URL。 [docs](http://flask.pocoo.org/docs/0.12/api/#flask.url_for) – jonafato
用_ _external = True解決了它# 謝謝你們。 – freefly0313
@jonafato酷!我以前從未使用'_external',但它看起來非常有用!不知道它是否總能按預期工作(例如,如果你使用Flask來提供兩個不同的主機名,'_external'使用'SERVER_NAME',它將是'localhost'或'0.0.0.0'或者其中一個主機名或者其他東西你可能希望在請求進入這個路由的同一個主機名上發出這個請求,在這種情況下,你需要在請求前添加'base_url'到相對的'url_for'路徑。 @ freefly0313很高興你的工作! –