码迷,mamicode.com
首页 > 其他好文 > 详细

后宫佳丽三千 ,小系统,不完善!!!

时间:2018-11-19 17:27:50      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:pos   into   ntb   sub   def   image   har   test   use   

用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

 

后宫佳丽三千 ,小系统,不完善!!!

标签:pos   into   ntb   sub   def   image   har   test   use   

原文地址:https://www.cnblogs.com/nori/p/9983714.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!