要将保存的搜索条件格式化为HTML,可以使用字符串拼接的方法将搜索条件中的关键信息以HTML的形式呈现出来。以下是一个简单的示例代码:
def format_search_condition(search_condition):
    html = ''
    html += '搜索条件
'
    html += ''
    for key, value in search_condition.items():
        html += f'- {key}: {value}
 '
    html += '
'
    html += ''
    return html
# 示例搜索条件
search_condition = {
    '关键词': '电脑',
    '价格范围': '1000-2000',
    '排序方式': '价格升序'
}
formatted_html = format_search_condition(search_condition)
print(formatted_html)
以上代码中,format_search_condition 函数接受一个保存的搜索条件的字典作为参数,然后通过字符串拼接的方式将搜索条件的关键信息以HTML的形式生成出来。最终返回的 html 变量包含了格式化后的HTML内容。
运行以上代码,将会输出如下格式的HTML内容:
    搜索条件
    
        - 关键词: 电脑
 
        - 价格范围: 1000-2000
 
        - 排序方式: 价格升序
 
    
你可以根据需要进一步调整HTML的样式和结构。