Open
Description
Description:
Accessing the root route /
triggers an internal server error (HTTP 500) due to an intentional exception in the code.
Steps to Reproduce:
- Run the Flask application using the provided code snippet.
- Open a web browser and navigate to
http://127.0.0.1:5000/
. - Observe the error message and stack trace in the browser or console.
Expected Behavior:
The root route /
should display the message "Welcome to your first Flask application!"
or handle the exception gracefully.
Actual Behavior:
An internal server error (HTTP 500) occurs, with the following error message:
Internal Server Error: /
Traceback (most recent call last):
File "<file_path>", line <line_number>, in home
raise Exception("Internal server error.")
Exception: Internal server error.
Code Snippet:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
raise Exception("Internal server error.")
return "Welcome to your first Flask application!"
if __name__ == '__main__':
app.run(debug=True)
Development Environment:
- OS: Ubuntu 24.04.
- Python Version: 3.12.3
- Flask Version: 3.0.3
Suggested Fix:
Handle the exception gracefully or remove the exception to ensure the route works as expected. Example fix:
@app.route('/')
def home():
try:
# Logic here
return "Welcome to your first Flask application!"
except Exception as e:
return f"An error occurred: {str(e)}", 500
Let me know if further details are needed!
Metadata
Metadata
Assignees
Labels
No labels