后宫佳丽三千 ,小系统,不完善!!!
Posted nori
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了后宫佳丽三千 ,小系统,不完善!!!相关的知识,希望对你有一定的参考价值。
用flask 主页:
1 import sqlite3 2 import random 3 from flask import Flask, render_template, url_for, redirect 4 5 from user_login import * 6 from flask import request 7 8 app = Flask(__name__) 9 10 11 12 13 14 @app.route(‘/‘, methods=[‘POST‘, ‘GET‘]) 15 def index(): 16 if request.method == ‘POST‘: 17 file = request.form[‘file‘] 18 name = request.form[‘name‘] 19 # insert(file, name) 20 res = adduser(file, name) 21 22 tt = isExisted() 23 e = random.randint(0, 1) 24 name =tt[e][1] 25 url = tt[e][0] 26 27 return render_template(‘index.html‘, name=name, url=url) 28 if __name__ == ‘__main__‘: 29 app.run()
html 页面:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>后宫佳丽三千 </title> <style> *{ margin: 0; padding: 0; } .box{ position: relative; width: 600px; height: 400px; margin:100px auto; text-align: center; font-family: "楷体"; font-size: 40px; } #moshuhe{ position: absolute; width: 600px; height: 400px; background-color: silver; display: block; } .box img{ width:600px; height: 400px; } .box label{ text-align: center; } .hide{ position: absolute; display: none; width: 200px; height: 100px; top:100px; left: 200px; background-color: #d9d9; opacity: 0.5; } #random{ position: absolute; top:120px; left: 260px; font-size: 100px; font-family: "楷体"; } </style> </head> <body> <div class="box"> <div> <div id="moshuhe"> <label id="random">10</label> </div> <img id="img" src="static/image/zhaoliying_01.jpg"> <label id="random_name"></label> </div> <div> <input type="button" value="开始翻牌" onclick="fanpai()"> <input type="button" value="纳妃" onclick="Show();" > <input type="button" value="刷新" onclick="location.reload()" > </div> <form class="hide" id="hide" method="post" > <input type="file" directory id="file" name="file"> <input type="text" placeholder="请输入姓名" name="name"> <input type="submit" name="提交" onclick="upload()"> <input type="button" value="退出" onclick="Hide();"> </form> </div> <script> function Show() { var show= document.getElementById(‘hide‘); show.style.display ="block"; } function Hide() { var hide =document.getElementById(‘hide‘); hide.style.display="none"; } function fanpai() { var show = document.getElementById(‘img‘); var random = document.getElementById(‘random‘); var moshu = document.getElementById(‘moshuhe‘); var name = document.getElementById(‘random_name‘); var i=10; setInterval(function () { i--; if(i>0) { random.innerHTML = i; } else if(i==0){ moshu.style.display="none"; name.innerHTML="{{ name }}"; } }, 800) show.src="static/image/{{ url }}"; return 0; } </script> </body>
链接数据库:mysql
import pymysql conn = pymysql.connect("localhost", "root", "******", "test") cur = conn.cursor() def adduser(username,password): sql = "insert into test.user(username, password) values (‘%s‘ , ‘%s‘);" % (username, password) cur.execute(sql) conn.commit() conn.close() def isExisted(): sql = "select username, password from test.user " cur.execute(sql) res = cur.fetchall() return res
以上是关于后宫佳丽三千 ,小系统,不完善!!!的主要内容,如果未能解决你的问题,请参考以下文章