Messiry
Posts: 16
Joined: Sun Oct 02, 2016 3:34 pm

flask web server issue

Fri Oct 28, 2016 11:52 pm

hello there , i'm having an issue with flask web server & i hope to find a solution here ,

i'm trying to use GET & POST methods from an html page but whenever i try to run the server this error appears

Code: Select all

File "app.py", line 23, in <module>
@app.route('/login', methods['GET','POST'])
NameError: name 'methods' is not defined
here is my simple web server app

Code: Select all

from flask import Flask , render_template , flash 
from flask import request

import datetime

from db_connect import connection



app = Flask(__name__)

@app.route('/')
def homepage ():
	now = datetime.datetime.now()
	timeString = now.strftime("%Y-%m-%d %H:%M")
	templateData = {
	'title' : 'HELLO!',
	'time': timeString
	}
	return render_template('hello.html', **templateData )


@app.route('/login', methods['GET','POST'])   
def login_page():
	error = None 
	try:
		if request.method == "POST" :
			attempted_username= request.form['username']
			attempted_password= request.form['password']
			if attempted_password == "password" and attempted_username == "username" :
				return('you just used a Post request ')
			else:
				error="invalid password" 
		return render_template("login.html", error = error)
	except :
		return render_template("login.html", error = error)

@app.route('/mydb')
def connect_mydb() :
	try:
		dbname = "office"
		c, conn = connection(dbname)
		return ("connected to DB "+ dbname)
	except:
		return "error" 

if __name__ == '__main__' :
    app.run( host='0.0.0.0', debug=True)


so this error of ' methods ' undefined name why does it appear , i searched google and nothing came across like this error over here .

Return to “Beginners”