Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions .idea/MySystem.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .streamlit/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[server]
maxUploadSize = 10240
runOnSave = true
cookieSecret = "HUSTOROP"
enableXsrfProtection = true

[ui]
hideTopBar = false

[browser]
serverAddress = "0.0.0.0"
Binary file added __pycache__/app_init.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/database.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/decorators.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/extensions.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/global_variable.cpython-39.pyc
Binary file not shown.
21 changes: 21 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from flask import redirect, url_for, session, g
from database import UserModel
from app_init import *


@app.route('/')
def index():
return redirect(url_for("user.login"))


@app.before_request
def before_request():
username = session.get("user")
if username:
# 给全局变量g绑定参数
# setattr(g, "user", user)
g.user = username


if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001, debug=True)
123 changes: 123 additions & 0 deletions app_config/ConfigParser.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
一、ConfigParser简介
ConfigParser 是用来读取配置文件的包。配置文件的格式如下:中括号“[ ]”内包含的为section。section 下面为类似于key-value 的配置内容。

[db]
db_host = 127.0.0.1
db_port = 69
db_user = root
db_pass = root
host_port = 69

[concurrent]
thread = 10
processor = 20
括号“[ ]”内包含的为section。紧接着section 为类似于key-value 的options 的配置内容。




二、ConfigParser 初始化对象
使用ConfigParser 首选需要初始化实例,并读取配置文件:
import configparser
config = configparser.ConfigParser()
config.read("ini", encoding="utf-8")
三、ConfigParser 常用方法

1、获取所用的section节点


# 获取所用的section节点
import configparser
config = configparser.ConfigParser()
config.read("ini", encoding="utf-8")
print(config.sections())
#运行结果
# ['db', 'concurrent']

2、获取指定section 的options。即将配置文件某个section 内key 读取到列表中:


import configparser
config = configparser.ConfigParser()
config.read("ini", encoding="utf-8")
r = config.options("db")
print(r)
#运行结果
# ['db_host', 'db_port', 'db_user', 'db_pass', 'host_port']

3、获取指点section下指点option的值


import configparser
config = configparser.ConfigParser()
config.read("ini", encoding="utf-8")
r = config.get("db", "db_host")
# r1 = config.getint("db", "k1") #将获取到值转换为int型
# r2 = config.getboolean("db", "k2" ) #将获取到值转换为bool型
# r3 = config.getfloat("db", "k3" ) #将获取到值转换为浮点型
print(r)
#运行结果
# 127.0.0.1

4、获取指点section的所用配置信息


import configparser
config = configparser.ConfigParser()
config.read("ini", encoding="utf-8")
r = config.items("db")
print(r)
#运行结果
#[('db_host', '127.0.0.1'), ('db_port', '69'), ('db_user', 'root'), ('db_pass', 'root'), ('host_port', '69')]


5、修改某个option的值,如果不存在则会出创建


# 修改某个option的值,如果不存在该option 则会创建
import configparser
config = configparser.ConfigParser()
config.read("ini", encoding="utf-8")
config.set("db", "db_port", "69") #修改db_port的值为69
config.write(open("ini", "w"))


运行结果
6、检查section或option是否存在,bool值

import configparser
config = configparser.ConfigParser()
config.has_section("section") #是否存在该section
config.has_option("section", "option") #是否存在该option
7、添加section 和 option


import configparser
config = configparser.ConfigParser()
config.read("ini", encoding="utf-8")
if not config.has_section("default"): # 检查是否存在section
config.add_section("default")
if not config.has_option("default", "db_host"): # 检查是否存在该option
config.set("default", "db_host", "1.1.1.1")
config.write(open("ini", "w"))


运行结果
8、删除section 和 option

import configparser
config = configparser.ConfigParser()
config.read("ini", encoding="utf-8")
config.remove_section("default") #整个section下的所有内容都将删除
config.write(open("ini", "w"))
运行结果
9、写入文件

以下的几行代码只是将文件内容读取到内存中,进过一系列操作之后必须写回文件,才能生效。

import configparser
config = configparser.ConfigParser()
config.read("ini", encoding="utf-8")
写回文件的方式如下:(使用configparser的write方法)

config.write(open("ini", "w"))
Empty file added app_config/__init__.py
Empty file.
Binary file added app_config/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added app_config/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added app_config/__pycache__/config.cpython-38.pyc
Binary file not shown.
Binary file added app_config/__pycache__/config.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
50 changes: 50 additions & 0 deletions app_config/app_config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[PATHS]
;if USER_ROOT is None -> path of dfweb.py
USER_ROOT = None

[SQLALCHEMY]
;POSTGRES_* should be None if we dont want to use postgres
# 使用PostgreSQL
POSTGRES_HOSTNAME=localhost
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=050203
POSTGRES_DATABASE=postgres
POSTGRES_PORT=8080
# 使用MySQL
MYSQL_HOSTNAME=None
MYSQL_USERNAME=None
MYSQL_PASSWORD=None
MYSQL_DATABASE=None
MYSQL_PORT=None

DB_HOST = sqlite:///username.db
TRACK_MODIFICATIONS = True


[FLASK]
JSON_SORT_KEYS = False
DEBUG = True
THREADED = True
HOST = 127.0.0.1
PORT = 5001

;SERVER_NAME = None
;APPLICATION_ROOT = /


[APP]
SAMPLE_DATA_SIZE = 5
MAX_FEATURES = 10
MAX_CATEGORICAL_SIZE = 2000
MAX_RANGE_SIZE = 100
MIN_RANGE_SIZE = 10

[DEFAULT_PARAMS]
num_epochs = 100
batch_size = 32
optimizer = Adam
learning_rate = 0.01
throttle = 1
save_summary_steps = 5
save_checkpoints_steps = 50
keep_checkpoint_max = 5
11 changes: 11 additions & 0 deletions app_config/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 配置邮件
MAIL_SERVER = 'smtp.163.com'
MAIL_PORT = 465
MAIL_USE_TLS = False
MAIL_USE_SSL = True
MAIL_DEBUG = True
MAIL_USERNAME = "lu_0523@163.com"
MAIL_PASSWORD = "NCFLMESPHRXRKPQG"
MAIL_DEFAULT_SENDER = "lu_0523@163.com"
MAIL_MAX_EMAILS = None
MAIL_ASCII_ATTACHMENTS = False
Loading