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代码

相关推荐
摇滚侠3 小时前
《SpringBoot 3:入门与应用实战》第 12 章 JDBC 与事务 使用 JdbcTemplate 阅读笔记 32
spring boot·笔记·后端
步行cgn4 小时前
@Configuration 详解:Spring 配置类的核心注解
java·后端·spring
桦说编程6 小时前
【AtomicAgent系列1】变异测试——过去做不起,现在 agent 做得起
后端·ai编程·vibecoding
考虑考虑7 小时前
nginx打印请求日志
运维·后端·nginx
IT_陈寒7 小时前
Python的切片赋值把我坑惨了,这不是bug是特性
前端·人工智能·后端
CoderLiu7 小时前
程序化工具调用(PTC)与动态工作流引擎:深入大模型工具调用的架构演进与实践
前端·人工智能·后端
fireworks998 小时前
SpringBoot2接入Knife4j
后端
wei_shuo8 小时前
数据迁移工具实战:KDMS自动化评估与量化决策体系解析
后端
Lightpwd9 小时前
Spring Boot 多数据源落地:AbstractRoutingDataSource + 注解切面(附源码)
数据库·后端
乱码三千9 小时前
使用ComfyUI+MinMax-H3音视频模型生成视频
前端·后端·github