1、安装ConfigParserpip install ConfigParser
2、在django目录配置ini文件的路径TEST_CONF_DIR = os.path.join(BASE_DIR, "common/conf/test_conf.ini")
3、写一个ini文件到公共目录
common/conf/test_conf.ini[test_robot_conf]
robot_servergroup_hz = test1
robot_servergroup_bj = test2
robotversionid = test1.0
robotagentid = test2.0
test_url = http://www.test.com/
4、views层获取数据
website/views.pyimport configparser
test_path = settings.TEST_CONF_DIR
print("test_path",test_path)
cf = configparser.ConfigParser()
cf.read('test_path')
test_urls = cf.get("test_robot_conf", "test_url") # 读取配置文件
print("test_urls", test_urls)