Reputation: 197
I've tried to use this line in Python3 (Flask) project, which is UTF-8 encoding:
@app.route('/@<username>', methods=['GET', 'POST'])
But in browser address bar, it always displays like:
http://example.com/%40username
How to display the original '@' in browser address bar? thanks!
Upvotes: 2
Views: 1798
Reputation: 931
Are you are using url_for from python code? One approach in such case is to call urllib.unquote on return value of url_for
Sample code:
from flask import Flask, url_for, redirect
import urllib
app = Flask(__name__)
@app.route("/")
def hello():
return redirect(urllib.unquote(url_for('user', username='test')))
@app.route('/@<username>', methods=['GET', 'POST'])
def user(username):
return "Hello %s" % (username)
if __name__ == "__main__":
app.run()
Disabling character escaping is discussed here
Upvotes: 1