I'm making a Python script, opening a link that asks for a username and password and a login button which shows you your details, showing that the process have been completed. My problem is that, though the login page works, it gives a KeyError when I press the login button. Here's my code: from flask import Flask, request, redirect, url_for app = Flask(__name__) @app.route('/') def RedirectToLogin(): return redirect(url_for('login')) @app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] return ''' <html> <head> <style> .details-container { display: flex; justify-content: center; align-items: center; height: 100vh; font-size: 24px; text-align: center; } .form-container { display: flex; flex-direction: column; width: 200px; margin: 0 auto; } .form-input { margin-bottom: 10px; } .smooth-button { border-radius: 12px; padding: 10px 20px; background-color: black; color: white; border: none; cursor: pointer; margin-top: 20px; } .smooth-button:hover { background-color: #45a049; } </style> </head> <body> <div class="details-container"> <div> <p>Username: {0}</p> <p>Password: {1}</p> </div> </div> </body> </html> '''.format(username, password) return ''' <html> <head> <style> .form-container { display: flex; flex-direction: column; width: 200px; margin: 0 auto; } .form-input { margin-bottom: 10px; } .smooth-button { border-radius: 12px; padding: 10px 20px; background-color: black; color: white; border: none; cursor: pointer; margin-top: 20px; } .smooth-button:hover { background-color: #45a049; } </style> </head> <body> <form method="post" action="/login" class="form-container"> <label for="username">Username:</label> <input type="text" id="username" name="username" class="form-input"><br> <label for="password">Password:</label> <input type="password" id="password" name="password" class="form-input"><br> <input type="submit" value="Login" class="smooth-button"> </form> </body> </html> ''' if __name__ == '__main__': app.run(debug=True) What I expected: Username: [User input for username] Password: [User input for password] [Login] <---- button Username: [Inputted username] Password: [Inputted password] What I got Username: [User input for username] Password: [User input for password] [Login] <---- button ## KeyError ## KeyError: '\n display' Traceback (most recent call last) File "C:\Users\ABC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\flask\app.py", line 1498, in __call__ return self.wsgi_app(environ, start_response) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ABC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\flask\app.py", line 1476, in wsgi_app response = self.handle_exception(e) ^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ABC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\flask\app.py", line 1473, in wsgi_app response = self.full_dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ABC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\flask\app.py", line 882, in full_dispatch_request rv = self.handle_user_exception(e) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ABC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\flask\app.py", line 880, in full_dispatch_request rv = self.dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ABC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\flask\app.py", line 865, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "c:\Users\ABC\Desktop\VsCode Projects\Python Projects\Login-Page-with-Flask.py", line 59, in login '''.format(username, password) ^^^^^^^^^^^^^^^^^^^^^^^^^^Open an interactive python shell in this frame KeyError: '\n display' The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error. To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side. You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection: dump() shows all variables in the frame dump(obj) dumps all that's known about the object How to resolve this? Continue reading...