Search code examples
pythonflaskinternal-server-error

Low Security Password/Username Concept Flask Security Error


Basically just trying to make a simple login page that has pretty much no security but keep getting internal server errors, any help with where I'm going wrong would be much appreciated. I've tried searching around but I can't find anything. I'm also pretty new to Python, so go easy :)

Python/Flask:

@app.route('/adminlogin')
def admin():
    return render_template('adminlogin.html')

@app.route('/adminDetails', methods =['POST'])  
    def adminLogin():
        correctUser = 'admin'
        correctPass = 'Password1'
        username = request.form['username']
        password = request.form['password']

    if username == correctUser & password == correctPass:
        adminSuccess()
    else: 
        admin()


@app.route('/admin')
def adminSuccess():
    return render_template('admin.html')

HTML:

<form action="/adminDetails" method="post">
        Username<input name="username" type = "text" maxlength="32" size="12" placeholder="Username" required><br>
        Password<input name ="password" type="password" maxlength="20" size="12" placeholder="Password" required><br>
        <button class ="menuitem" type="submit" value="submit">Submit</button>
        <button class="menuitem" type ="reset" value ="Clear">Clear</button>
    </form>

Traceback:

 Traceback (most recent call last):
      File "C:\Users\\AppData\Local\Programs\Python\Python35-32\lib\site-    packages\flask\app.py", line 1836, in __call__ 
    return self.wsgi_app(environ, start_response)
  File "C:\Users\\AppData\Local\Programs\Python\Python35-32\lib\site-packages\flask\app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "C:\Users\\AppData\Local\Programs\Python\Python35-32\lib\site-packages\flask\app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\\AppData\Local\Programs\Python\Python35-32\lib\site-packages\flask\_compat.py", line 33, in reraise
    raise value
  File "C:\Users\\AppData\Local\Programs\Python\Python35-32\lib\site-packages\flask\app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\\AppData\Local\Programs\Python\Python35-32\lib\site-packages\flask\app.py", line 1478, in full_dispatch_request
    response = self.make_response(rv)
  File "C:\Users\\AppData\Local\Programs\Python\Python35-32\lib\site-packages\flask\app.py", line 1566, in make_response
        raise ValueError('View function did not return a response')
    ValueError: View function did not return a response

Solution

  • Since I can't comment, I have to leave this piece advice in the answer section.
    You should try running your app with debug set to true. This would give you the whole traceback of what caused the error instead of "Internal server error"

    app.run(debug=True)
    

    Post the traceback and we'll all be in a better position to help you.

    Edit: Your traceback says that your view function doesn't actually return anything. They need to return some kind of response. So what you need to do is return those function calls in your if else statements in your adminLogin() view