1. Py2.7,flask framework used by the development environment in pycharm,
2. During development, you create the flask project directly in pycharm
code as follows:
3. The phenomenon is that the port is specified or the ip is set together with the port to access /?
app.run not found on user=xxx error 404 page (
host = "0.0.0.0",
port = 7777,
debug = True
)
< hr >
< H1 >! / usr/bin/python < / H1 >
< H1 >--coding: UTF-8--< / H1 >
import pyotp
import MySQLdb
import time
from flask import Flask
from flask.ext.httpauth import HTTPBasicAuth
from flask import request
import json
from threading import Timer
auth = HTTPBasicAuth ()
app = Flask (_ _ name__)
def dingshi (USER):
db = MySQLdb.connect("localhost", "root", "xxxxx", "flask")
cursor = db.cursor()
BASE = pyotp.random_base32()
totp = pyotp.TOTP("%s" % BASE)
PASSWD = totp.now()
sql4 = "delete from users where name="%s"" % USER
cursor.execute(sql4)
db.commit()
print ""
db.close()
print ""
@ app.route ("/")
def getvpnpasswd ():
VPNUSER = request.args.get("user")
BASE = pyotp.random_base32()
totp = pyotp.TOTP("%s" % BASE)
PASSWD = totp.now()
< H1 > Open database connection < / H1 >
db = MySQLdb.connect("localhost","root","asin7SGAcdB12ci^t5987.com","flask" )
< H1 > use the cursor () method to get operation cursors < / H1 >
cursor = db.cursor()
< H1 > SQL query statement < / H1 >
sql1 = "SELECT name FROM users where name="%s"" %VPNUSER
sql5 = "select passwd from users where name="%s"" %VPNUSER
< H1 > sql insert < / H1 >
sql2 = ("insert into users(name) values("%s")" %VPNUSER)
sql3 = "update users set passwd="%s" where name="%s"" %(PASSWD,VPNUSER)
< H1 > try: < / H1 >
cursor.execute(sql1)
< H1 > results = cursor.fetchone () < / H1 >
results = cursor.fetchall()
if results:
print "have data"
cursor.execute(sql5)
db.commit()
db.close()
result_now = cursor.fetchall()
-sharp print result_now[0][0]
result = {
"VPNUSER": VPNUSER,
"PASSWD": result_now[0][0]
}
Timer(280, dingshi,[VPNUSER]).start()
print ""
return json.dumps(result)
else:
print "no data"
cursor.execute(sql2)
cursor.execute(sql3)
db.commit()
print "yijing charu"
db.close()
result = {
"VPNUSER": VPNUSER,
"PASSWD": PASSWD
}
Timer(280, dingshi,[VPNUSER]).start()
print ""
return json.dumps(result)
if name ="_ _ main__":
app.run()
< hr >