資源簡介
后臺管理系統 v1.0.0 這是一篇用Python所做的公司網站后臺的管理系統

代碼片段和文件信息
#!/usr/bin/evn?python
#?coding=utf-8
import?bottle
import?sys
import?os
import?logging
import?urllib.parse
from?bottle?import?default_app?get?run?request?hook
from?beaker.middleware?import?SessionMiddleware
#?導入工具函數包
from?common?import?web_helper?log_helper
#?導入api代碼模塊(初始化api文件夾里的各個訪問路由,這一句不能刪除,刪除后將無法訪問api文件夾里的各個接口)
import?api
#############################################
#?初始化bottle框架相關參數
#############################################
#?獲取當前main.py文件所在服務器的絕對路徑
program_path?=?os.path.split(os.path.realpath(__file__))[0]
#?將路徑添加到python環境變量中
sys.path.append(program_path)
#?讓提交數據最大改為2M(如果想上傳更多的文件,可以在這里進行修改)
bottle.baseRequest.MEMFILE_MAX?=?1024?*?1024?*?2
#############################################
#?初始化日志相關參數
#############################################
#?如果日志目錄log文件夾不存在,則創建日志目錄
if?not?os.path.exists(‘log‘):
????os.mkdir(‘log‘)
#?初始化日志目錄路徑
log_path?=?os.path.join(program_path?‘log‘)
#?定義日志輸出格式與路徑
logging.basicConfig(level=logging.INFO
????????????????????format=‘%(asctime)s?%(filename)s[line:%(lineno)d]?%(levelname)s?%(message)s‘
????????????????????filename=“%s/info.log“?%?log_path
????????????????????filemode=‘a‘)
#?設置session參數
session_opts?=?{
????‘session.type‘:?‘file‘
????‘session.cookie_expires‘:?3600
????‘session.data_dir‘:?‘/tmp/sessions/simple‘
????‘session.auto‘:?True
}
@hook(‘before_request‘)
def?validate():
????“““使用勾子處理接口訪問事件“““
????#?獲取當前訪問的Url路徑
????path_info?=?request.environ.get(“PATH_INFO“)
????#?過濾不用做任何操作的路由(即過濾不用進行判斷是否登錄和記錄日志的url)
????if?path_info?in?[‘/favicon.ico‘?‘/‘?‘/api/verify/‘]:
????????return
????###?記錄客戶端提交的參數?###
????#?獲取當前訪問url路徑與ip
????request_log?=?‘url:‘?+?path_info?+?‘?ip:‘?+?web_helper.get_ip()
????try:
????????#?添加json方式提交的參數
????????if?request.json:
????????????request_log?=?request_log?+?‘?params(json):‘?+?urllib.parse.unquote(str(request.json))
????except:
????????pass
????try:
????????#?添加GET方式提交的參數
????????if?request.query_string:
????????????request_log?=?request_log?+?‘?params(get):‘?+?urllib.parse.unquote(str(request.query_string))
????????#?添加POST方式提交的參數
????????if?request.method?==?‘POST‘:
????????????request_log?=?request_log?+?‘?params(post):‘?+?urllib.parse.unquote(str(request.params.__dict__))
????????#?存儲到日志文件中
????????log_helper.info(request_log)
????except:
????????pass
????#?處理ajax提交的put、delete等請求轉換為對應的請求路由(由于AJAX不支持RESTful風格提交,所以需要在這里處理一下,對提交方式進行轉換)
????if?request.method?==?‘POST‘?and?request.POST.get(‘_method‘):
????????request.environ[‘REQUEST_METHOD‘]?=?request.POST.get(‘_method‘?‘‘)
????#?過濾不用進行登錄權限判斷的路由(登錄與退出登錄不用檢查是否已經登錄)
????url_list?=?[“/api/login/“?“/api/logout/“]
????if?path_info?in?url_list:
????????pass
????else:
????????#?已經登錄成功的用戶session肯定有值,沒有值的就是未登錄
????????session?=?web_helper.get_session()
????????#?獲取用戶id
????????manager_id?=?session.get(‘id‘?0)
????????login_name?=?session.get(‘login_name‘?0)
????????#?判斷用戶是否登錄
????????if?not?manager_id?or?not?login_na
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3513??2017-10-25?17:20??python\code\api\login.py
?????文件????????776??2017-10-24?20:09??python\code\api\verify.py
?????文件????????720??2016-12-20?10:29??python\code\api\__init__.py
?????文件???????2619??2017-09-30?14:47??python\code\common\convert_helper.py
?????文件???????3108??2017-09-30?16:56??python\code\common\datetime_helper.py
?????文件???????2990??2017-10-16?15:40??python\code\common\db_helper.py
?????文件????????256??2017-10-10?15:05??python\code\common\encrypt_helper.py
?????文件????????477??2016-11-03?19:33??python\code\common\except_helper.py
?????文件????????405??2017-05-31?15:10??python\code\common\json_helper.py
?????文件????????785??2017-09-28?17:32??python\code\common\log_helper.py
?????文件???????1523??2017-09-27?17:44??python\code\common\mail_helper.py
?????文件???????1779??2017-10-17?17:38??python\code\common\random_helper.py
?????文件???????5389??2017-10-18?16:05??python\code\common\string_helper.py
?????文件???????3056??2017-10-18?16:24??python\code\common\verify_helper.py
?????文件???????7078??2017-10-18?17:03??python\code\common\web_helper.py
?????文件????????616??2016-11-03?20:02??python\code\common\__init__.py
?????文件???????1258??2017-09-30?11:29??python\code\config\const.py
?????文件????????606??2016-12-20?10:30??python\code\config\__init__.py
?????文件???????4288??2017-10-25?17:08??python\code\main.py
?????文件???????7339??2017-10-13?11:34??python\code\test\convert_helper_test.py
?????文件???????3435??2017-09-30?17:22??python\code\test\datetime_helper_test.py
?????文件???????1435??2017-10-16?16:19??python\code\test\db_helper_test.py
?????文件????????852??2017-10-17?16:26??python\code\test\encrypt_helper_test.py
?????文件????????498??2017-10-17?16:26??python\code\test\except_helper_test.py
?????文件????????647??2017-10-17?16:26??python\code\test\json_helper_test.py
?????文件???????1506??2017-10-17?17:12??python\code\test\log_helper_test.py
?????文件????????656??2017-10-17?16:29??python\code\test\mail_helper_test.py
?????文件???????1166??2017-10-17?17:38??python\code\test\random_helper_test.py
?????文件???????3008??2017-10-18?16:01??python\code\test\string_helper_test.py
?????文件???????5277??2017-10-24?19:47??python\html\login.html
............此處省略12個文件信息
評論
共有 條評論