xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

  • 大小: 18KB
    文件類型: .zip
    金幣: 2
    下載: 1 次
    發(fā)布日期: 2021-06-18
  • 語言: 其他
  • 標(biāo)簽: python??flask??sqlite??

資源簡介

系統(tǒng)源碼,可直接實現(xiàn)。對應(yīng)文檔設(shè)計在個人上傳的另一資源中

資源截圖

代碼片段和文件信息

import?time
from?datetime?import?datetime
#日期相關(guān)操作,和time包連用表示、計算借還書日期

from?sqlite3?import?dbapi2?as?sqlite3
#使用SQLite時,它的功能直接被集成在其中,應(yīng)用會直接訪問包含數(shù)據(jù)的文件
#SQLITE功能簡約,小型化,追求最大磁盤效率;MYSQL功能全面,綜合化,追求最大并發(fā)效率。如果只是單機上用的,數(shù)據(jù)量不是很大,
#?需要方便移植或者需要頻繁讀/寫磁盤文件的話,就用SQLite比較合適;如果是要滿足多用戶同時訪問,或者是網(wǎng)站訪問量比較大是使用MYSQL比較合適.

from?flask?import?Flask?request?session?url_for?redirect?render_template?abort?g?flash?_app_ctx_stack

from?hashlib?import?md5
#這是加密函數(shù),將傳進來的函數(shù)加密
from?werkzeug?import?check_password_hash?generate_password_hash
#數(shù)據(jù)庫中直接存放明文密碼是很危險的Werkzeug庫中的security能夠方便的實現(xiàn)散列密碼的計算
#security庫中?generate_password_hash(passwordmethod...)函數(shù)將原始密碼作為輸入以字符串形式輸出密碼的散列值
#check_password_hash(hashpassword)函數(shù)檢查給出的hash密碼與明文密碼是否相符



#CONFIGURATION
DATAbase?=?‘book.db‘
DEBUG?=?True
SECRET_KEY?=?‘development?key‘
MANAGER_NAME?=?‘a(chǎn)dmin‘
MANAGER_PWD?=?‘123456‘

#?create?our?little?application?:
app?=?Flask(__name__)
app.config.from_object(__name__)

#設(shè)置一個名為?FLASKR_SETTINGS?環(huán)境變量來設(shè)定一個配置文件載入后是否覆蓋默認值。
#靜默開關(guān)告訴?Flask?不去關(guān)心這個環(huán)境變量鍵值是否存在。
app.config.from_envvar(‘FLASKR_SETTINGS‘?silent=True)

#數(shù)據(jù)庫連接
def?get_db():
top?=?_app_ctx_stack.top
if?not?hasattr(top?‘sqlite_db‘):
top.sqlite_db?=?sqlite3.connect(app.config[‘DATAbase‘])
top.sqlite_db.row_factory?=?sqlite3.Row
return?top.sqlite_db

#這個裝飾器的作用就是向請求上下文中注冊一個函數(shù),當(dāng)上下文銷毀時調(diào)用。
@app.teardown_appcontext
def?close_database(exception):
top?=?_app_ctx_stack.top
if?hasattr(top?‘sqlite_db‘):
top.sqlite_db.close()

#初始化數(shù)據(jù)庫
def?init_db():
with?app.app_context():
db?=?get_db()
with?app.open_resource(‘book.sql‘?mode=‘r‘)?as?f:
db.cursor().executescript(f.read())
db.commit()

#訪問數(shù)據(jù)庫
def?query_db(query?args=()?one=False):
cur?=?get_db().execute(query?args)
rv?=?cur.fetchall()
return?(rv[0]?if?rv?else?None)?if?one?else?rv

#通過用戶名(設(shè)置唯一,不可重名)給讀者id
def?get_user_id(username):
rv?=?query_db(‘select?user_id?from?users?where?user_name?=??‘?[username]?one=True)
return?rv[0]?if?rv?else?None


@app.before_request
def?before_request():
g.user?=?None
if?‘user_id‘?in?session:
g.user?=?session[‘user_id‘]

@app.route(‘/‘)
def?index():
return?render_template(‘index.html‘)

@app.route(‘/manager_login‘?methods=[‘GET‘?‘POST‘])
def?manager_login():
error?=?None
if?request.method?==?‘POST‘:
if?request.form[‘username‘]?!=?app.config[‘MANAGER_NAME‘]:
error?=?‘Invalid?username‘
elif?request.form[‘password‘]?!=?app.config[‘MANAGER_PWD‘]:
error?=?‘Invalid?password‘
else:
session[‘user_id‘]?=?app.config[‘MANAGER_NAME‘]
return?redirect(url_for(‘manager‘))
return?render_template(‘manager_login.html‘?error?=?error)

#讀者登錄
@app.route(‘/reader_login‘?methods=[‘GET‘?‘POST‘])
def?reader_login():
error?=?None
if?request.method?==?‘POST‘:
user?=?query_db(‘‘‘select?*?from?users?where?user_name?=??‘‘‘
[request.form[‘username‘]]?one=True)
if?user?is?None:
error?=?‘Invalid?username‘
elif?not?check_password_hash(user[‘pwd‘]?request.form[‘password‘]):
error?=?‘Invalid?password‘
else:
session[‘user_id‘]?=?user[‘user_n

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-01-24?12:30??BookLibrary-master\
?????文件???????15601??2018-10-22?16:55??BookLibrary-master\book.py
?????文件?????????883??2018-10-22?11:42??BookLibrary-master\book.sql
?????目錄???????????0??2019-01-24?12:30??BookLibrary-master\static\
?????文件????????3110??2014-03-27?12:28??BookLibrary-master\static\style.css
?????目錄???????????0??2019-01-24?12:30??BookLibrary-master\templates\
?????文件?????????280??2018-10-08?15:37??BookLibrary-master\templates\index.html
?????文件?????????434??2018-10-21?13:27??BookLibrary-master\templates\layout.html
?????文件?????????293??2014-03-27?12:28??BookLibrary-master\templates\manager.html
?????文件?????????931??2014-03-27?12:28??BookLibrary-master\templates\manager_book.html
?????文件????????1063??2014-03-27?12:28??BookLibrary-master\templates\manager_books.html
?????文件?????????822??2014-03-27?12:28??BookLibrary-master\templates\manager_books_add.html
?????文件?????????513??2014-03-27?12:28??BookLibrary-master\templates\manager_books_delete.html
?????文件?????????323??2014-03-27?12:28??BookLibrary-master\templates\manager_index.html
?????文件?????????604??2014-03-27?12:28??BookLibrary-master\templates\manager_login.html
?????文件?????????937??2014-03-27?12:28??BookLibrary-master\templates\manager_modify.html
?????文件?????????946??2014-03-27?12:28??BookLibrary-master\templates\manager_user_modify.html
?????文件?????????554??2014-03-27?12:28??BookLibrary-master\templates\manager_userinfo.html
?????文件?????????583??2014-03-27?12:28??BookLibrary-master\templates\manager_users.html
?????文件?????????416??2018-10-11?14:34??BookLibrary-master\templates\reader.html
?????文件?????????977??2014-03-27?12:28??BookLibrary-master\templates\reader_book.html
?????文件?????????706??2014-03-27?12:28??BookLibrary-master\templates\reader_histroy.html
?????文件?????????446??2014-03-27?12:28??BookLibrary-master\templates\reader_info.html
?????文件?????????681??2014-03-27?12:28??BookLibrary-master\templates\reader_login.html
?????文件?????????923??2014-03-27?12:28??BookLibrary-master\templates\reader_modify.html
?????文件????????1382??2014-03-27?12:28??BookLibrary-master\templates\reader_query.html
?????文件?????????932??2014-03-27?12:28??BookLibrary-master\templates\register.html

評論

共有 條評論