Streamlit - python 快速生成UI框架

参考文档:Streamlit docs

安装 streamlit 环境

  • python 项目下终端执行:pip install streamlit
  • 验证:streamlit hello , 有跳转即成功

完成

效果

  • py 代码

    api_test.py 复制代码
    import streamlit as st
    import requests
    
    st.title("接口测试器")
    
    # url 接口地址,默认本地启动的地址
    def test_api(url):
        try:
            response = requests.get(url)
            if response.status_code == 200:
                st.success(f"接口 {url} 请求成功!")
                try:
                    data = response.json()
                    st.json(data)
                except ValueError:
                    st.text("响应不是有效的 JSON 数据")
                    st.text(response.text)
            else:
                st.error(f"接口 {url} 返回错误状态码: {response.status_code}")
                st.text(response.text)
        except Exception as e:
            st.error(f"接口 {url} 请求失败: {e}")
    
    # 输入框和按钮1
    url1 = st.text_input("接口1 URL", "http://localhost:8080/ping")
    if st.button("发送请求 到接口1"):
        test_api(url1)
    
    st.markdown("---")  # 分割线
    
    # 输入框和按钮2
    url2 = st.text_input("接口2 URL", "http://localhost:8080/hello")
    if st.button("发送请求 到接口2"):
        test_api(url2)
    
    # 你可以继续添加更多输入框和按钮,方式类似
  • 运行:streamlit run .\api_test.py

  • UI 界面

tips

可以使用 AI 生成需要的UI代码

相关推荐
颜酱17 分钟前
# 02 | 搭骨架:用 LangGraph 编排 12 步工作流(思路)
前端·人工智能·后端
颜酱18 分钟前
02 | 搭骨架:用 LangGraph 编排 12 步工作流
前端·人工智能·后端
嘉伟桑1 小时前
Python调用电价API返回JSON示例:分时电价、现货电价和字段解析
后端
武子康2 小时前
Shippy:确定性工具、会话级 Sandbox 与 Live-Data Eval(4 类收敛 + 7 步实现方案 + 6 类评测指标)
前端·人工智能·后端
我叫黑大帅2 小时前
我为什么单一消费者的场景下,要用 Redis List 当消息队列?
redis·后端·面试
AskHarries2 小时前
文件上传系统
后端
止语Lab3 小时前
好的 DX 不等于少写代码——三种语言的摩擦力设计课
后端
吃饱了得干活3 小时前
别再手动解析 LLM 输出了!LangChain 四种结构化输出方案对比
后端·python·langchain
程序员天天困3 小时前
Arthas trace 命令怎么用?一行定位最慢那行代码
jvm·后端
Huiturn3 小时前
GPT 5.6 连续编码 10 小时,纯 Python 啃下 Word 二进制格式——doc2docx 实现拆解
后端