配置文件类似数据库,里面存有一些参数

大括号表示一个section 具体类似于mongodb中的collections
大括号下都是其option 也就是存入的数据 采用key-value模式存储
然后页面如图

将配置文件中的section和option都可以展示在页面上,并进行正常的增删查改
在此贴出全部代码:
from flask import Flask, request, render_template, redirect, url_for
import configparser
app = Flask(__name__)
app.secret_key = 'iii'
class ConfHadndle:
def __init__(self, conf_name):
self.conf_name = conf_name
self.config = configparser .ConfigParser()
self.config.read(conf_name)
# 获取所有节点
def get_sections(self):
return self.config.sections()
# 获取一个节点下所有键值对,返回字典形式
def get_items(self,section):
return dict(self.config.items(section))
# 获取某个value
def get_value(self,section, option):
return self.config.get(section, option)
#增加节点
def add_sections(self,section,enable,cloud_id,ip,type,sleep,api_type):
self.config.add_section(section)
self.config.set(section, "enable", enable)
self.config.set(section,

本文介绍如何通过页面操作修改本地的.ini配置文件。配置文件采用section-option的键值对存储方式,类似MongoDB的collections。文章提供代码示例,展示了在页面上对配置文件的增删查改功能,以便于他人参考和自我回顾。
最低0.47元/天 解锁文章
290

被折叠的 条评论
为什么被折叠?



