return redirect(url_for('www'))
काम करेगा अगर आप एक समारोह कहीं और इस तरह है:
@app.route('/welcome')
def www():
return render_template('www.html')
url_for
एक समारोह के लिए लग रहा है, तो आप इसे नाम समारोह आप कॉल करना चाहते हैं की गुजरती हैं। इस तरह यह के बारे में सोचो:
@app.route('/login')
def sign_in():
for thing in login_routine:
do_stuff(thing)
return render_template('sign_in.html')
@app.route('/new-member')
def welcome_page():
flash('welcome to our new members')
flash('no cussing, no biting, nothing stronger than gin before breakfast')
return redirect(url_for('sign_in')) # not 'login', not 'sign_in.html'
तुम भी, return redirect('/some-url')
कर सकता है कि अगर याद करने के लिए आसान है। यह भी संभव है कि आप अपनी पहली पंक्ति को देखते हुए, केवल return render_template('www.html')
है।
और यह भी, नहीं नीचे shuaiyuancn की टिप्पणी से, अगर आप ब्लूप्रिंट उपयोग कर रहे हैं, url_for
url_for(blueprint_name.func_name)
के रूप में लागू किया जाना चाहिए। See documentation here।
मैं देख रहा हूँ, वास्तव में आप bvmou veru बहुत धन्यवाद। – chenge
+1 एक बहुत स्पष्ट उदाहरण के लिए ... और "नाश्ते से पहले जीन से मजबूत कुछ भी नहीं" –
प्रबुद्ध! मुझे लगा कि तर्क यूआरएल है .. – swdev