skip to Main Content

When I Run My Code On Python Using Flask, It Says ‘500, internal server error’
I searched everywhere but still, it doesn’t work, i didn’t find the answer to what happened. Does anyone know what the problem is, If Yes, answer and send me an message on discord: miledhomairah
This Is My Code:

from flask import Flask
from logging import FileHandler,WARNING
# To Run Enter ( python3 -m flask run --host=192.168.1.108 ) in CMD Terminal 
from flask import render_template
app = Flask(__name__, template_folder="templates")
file_handler = FileHandler('errorlog.txt')
file_handler.setLevel(WARNING)
#@app.host("192.168.1.115")
@app.route("/")
@app.route("/<name>")
@app.route("/home/")
@app.route("/login/")
def hello_world():
    return render_template('hello.html', person=name)
@app.errorhandler(404)
def pageNotFound(error):
    return "404 Page Not Found :("

OutPut

* Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://192.168.1.108:5000
Press CTRL+C to quit
[2024-11-24 16:39:35,880] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "C:UsersHPAppDataLocalPackagesPythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0LocalCachelocal-packagesPython313site-packagesflaskapp.py", line 1511, in wsgi_app
    response = self.full_dispatch_request()
  File "C:UsersHPAppDataLocalPackagesPythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0LocalCachelocal-packagesPython313site-packagesflaskapp.py", line 919, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:UsersHPAppDataLocalPackagesPythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0LocalCachelocal-packagesPython313site-packagesflaskapp.py", line 917, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:UsersHPAppDataLocalPackagesPythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0LocalCachelocal-packagesPython313site-packagesflaskapp.py", line 902, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "C:Phishing Websiteapp.py", line 13, in hello_world
    return render_template('hello.html', person=name)
                                                ^^^^
NameError: name 'name' is not defined
192.168.1.108 - - [24/Nov/2024 16:39:35] "GET / HTTP/1.1" 500 -

enter image description here

I tried alot of things to fix it but it didn’t work
I was expecting it to display the folowing:
HTML:

<!DOCTYPE html>
 <html>
    <link rel="stylesheet" href="style.css">
    <title>Login To HackerForums</title>
    <div> 
        <H1>Login</H1><br> 
        <label>Username <br>
            <input> <br>
         <label>Password <br>
             <input> <br>
              <button>submit</button>
             </div>

               </html>

CSS:

div{
    border-radius: 10px; 
    text-align: center; 
    position: absolute; 
    background-color: gray
}
*{
    text-align: center; 
    font-family: sans-serif;
} 
button{
    color: green; 
    background-color: green; 
    border-radius: 10px
} 

2

Answers


  1. Chosen as BEST ANSWER

    Turns Out That The Code Is Correct, I Entered "hello.html" when The File Was "index.html"


  2. If a route contains variables (in this case <name>), you should declare those as actual parameters of the view function:

    @app.route("/<name>")
    def hello_world(name):
        ...
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search