You have to return a redirect:
import os from flask import Flask,redirect app = Flask(__name__) @app.route('/') def hello(): return redirect("http://www.example.com", code=302) if __name__ == '__main__': # Bind to PORT if defined, otherwise default to 5000. port = int(os.environ.get('PORT', 5000)) app.run(host='0.0.0.0', port=port)
See the documentation on flask docs. The default value for code is 302 so code=302
can be omitted or replaced by other redirect code (one in 301, 302, 303, 305, and 307).
Related Posts:
- json.dumps vs flask.jsonify
- Internal Redirect in Flask
- Get the data received in a Flask request
- Get the data received in a Flask request
- ImportError: cannot import name
- Flask Template Not found
- Return JSON response from Flask view
- Flask ImportError: No Module Named Flask
- ModuleNotFoundError: No module named ‘MySQLdb’
- Flask ImportError: No Module Named Flask
- Flask ImportError: No Module Named Flask
- ImportError: No Module Named bs4 (BeautifulSoup)
- Flask raises TemplateNotFound error even though template file exists
- ImportError: No module named MySQLdb
- Flask example with POST
- Where do I get a SECRET_KEY for Flask?
- How can I get the named parameters from a URL using Flask?
- Flask Error: “Method Not Allowed The method is not allowed for the requested URL”
- In Flask, what is “request.args” and how is it used?
- In Flask, what is “request.args” and how is it used?
- How does ajax work with python?
- Trying to run Flask app gives “Address already in use”
- jinja2.exceptions.TemplateNotFound error [duplicate]
- How to serve static files in Flask
- python flask import error
- How do I get Flask to run on port 80?
- python-How to set global variables in Flask?
- How to get POSTed JSON in Flask?
- Flask Value error view function did not return a response [duplicate]
- Flask-framework: MVC pattern
- Create dynamic URLs in Flask with url_for()
- File “/usr/bin/pip”, line 9, in
from pip import main ImportError: cannot import name main - SyntaxError: unexpected EOF while parsing
- Converting list to numpy array
- How do I parse a string to a float or int?
- Check if something is (not) in a list in Python
- How to parse data in JSON format?
- TypeError: unhashable type: ‘dict’
- ‘Conda’ is not recognized as internal or external command
- Python list of dictionaries search
- Extract file name from path, no matter what the os/path format
- How do you do natural logs (e.g. “ln()”) with numpy in Python?
- sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype(‘float64’)
- What is print(f”…”)
- Convert Python dict into a dataframe
- Python AttributeError: ‘str’ object has no attribute ‘decode’
- NameError: name ‘raw_input’ is not defined
- Remove all whitespace in a string
- Pandas how to use pd.cut()
- What is the difference between list and list[:] in python?
- How to Read .txt in Pandas
- Why am I getting AttributeError: Object has no attribute?
- OSError [Errno 22] invalid argument when use open() in Python
- SBOX_FATAL_MEMORY_EXCEEDED error shown when Chromedriver turned 1800-1900 pages using Selenium
- Pinging servers in Python
- How can I use Python to get the system hostname?
- What is the difference between Anaconda and Pycharm?
- The tilde operator in Python
- Explain __dict__ attribute
- How to pretty print nested dictionaries?
- Is there a linked list predefined library in Python?
- return, return None, and no return at all?
- What does [:-1] mean/do in python? [duplicate]
- Displaying better error message than “No JSON object could be decoded”
- How do I check if a string is a number (float)?
- How are Pipfile and Pipfile.lock used?
- Dictionary in a numpy array?
- Pythonic way to find maximum value and its index in a list?
- ‘pip install’ fails for every package (“Could not find a version that satisfies the requirement”) [duplicate]
- Spyder Not Launching
- Python Pandas ValueError Arrays Must be All Same Length
- Anaconda / Python: Change Anaconda Prompt User Path
- Pycharm and sys.argv arguments
- ImportError: No module named ‘yaml’
- TypeError: ‘_io.TextIOWrapper’ object is not subscriptable
- super(type, obj): obj must be an instance or subtype of type
- What does “hashable” mean in Pytho
- Python multiprocessing.Pool: AttributeError
- Convert string to ASCII value python
- “Divide by zero encountered in log” when not dividing by zero
- How to include external Python code to use in other files?
- RSA encryption and decryption in Python
- pip3 error – ‘_NamespacePath’ object has no attribute ‘sort’
- What does {0} mean in this Python string?
- Tab Error in Python
- Installation of pygame with Anaconda
- Is there a Python equivalent of the C# null-coalescing operator?
- Python 3.6 import requests
- Tensorflow 2.0 – AttributeError: module ‘tensorflow’ has no attribute ‘Session’
- What is key=lambda
- Extract a part of the filepath (a directory) in Python
- What is the meaning of “int(a[::-1])” in Python?
- Pandas unstack problems: ValueError: Index contains duplicate entries, cannot reshape
- How do I read image data from a URL in Python?
- Python: Convert timedelta to int in a dataframe
- Can’t concat bytes to str
- Invalid syntax when using “print”?
- Error loading MySQLdb module: No module named ‘MySQLdb’
- Unable to install boto3
- Python MySQLdb not importing