1.编写网站源文件

index文件:网页源代码
app.py文件:上传api_key,展示网页,接收ds回答传回网页

2.使用后端调用方案

  1. 获取API key
  2. 编写后端代码(AI生成)
  3. 运行app.py文件
    此处出现错误:无法下载部分库
    错误原因:Centos系统内置为python版本低于3.6
    解决方法:将更换服务器为Ubuntu系统
    //部分报错内容
    C:\Users\Admin01\Desktop\web>pip install flask-cors Looking in indexes:        https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple ERROR: Could not find a version that satisfies the requirement flask-cors (from versions: none) ERROR: No matching distribution found for flask-cors
    
  4. 运行后进入http://127.0.0.1:5000即可在本地访问网站

3.将网站部署至云服务器

  1. 使用XSHELL连接至云服务器
  2. 在服务器中安装环境和网站依赖:
    此处出现错误:无法下载部分依赖
    错误原因:Centos系统内置为python版本低于3.6
    解决方法:将更换服务器为Ubuntu系统
//部分报错代码
Could not find a version that satisfies the requirement pandas>=1.2.3 (from openai) (from versions: 0.1, 0.2, 0.3.0, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.5.0, 0.6.0, 0.6.1, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.8.0, 0.8.1, 0.9.0, 0.9.1, 0.10.0, 0.10.1, 0.11.0, 0.12.0, 0.13.0, 0.13.1, 0.14.0, 0.14.1, 0.15.0, 0.15.1, 0.15.2, 0.16.0, 0.16.1, 0.16.2, 0.17.0, 0.17.1, 0.18.0, 0.18.1, 0.19.0, 0.19.1, 0.19.2, 0.20.0, 0.20.1, 0.20.2, 0.20.3, 0.21.0, 0.21.1, 0.22.0, 0.23.0, 0.23.1, 0.23.2, 0.23.3, 0.23.4, 0.24.0, 0.24.1, 0.24.2, 0.25.0, 0.25.1, 0.25.2, 0.25.3, 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5) No matching distribution found for pandas>=1.2.3 (from openai)

此处出现错误:无法下载部分依赖
错误原因: Ubuntu系统限制直接使用pip安装系统包
解决方法:创建独立的虚拟环境
重点报错代码:error: externally-managed-environment

Error: Unable to locate package flask
Error: Unable to locate package flask-cors
Error: Unable to locate package openai
root@iZbp1aj7736y0d7s8zt854Z:~/my_chat_website# pip3 install flask flask-cors openai
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.
    
    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.
    
    See /usr/share/doc/python3.14/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
  1. 设置环境变量 保护API KEY

  2. 启动app.py程序

  3. 尝试用公网IP访问网站
    此处出现错误:访问公网地址拒绝连接
    错误原因: 服务器尚未开放5000端口**
    解决方法:入规则管理中打开5000端口

    此处出现错误:本地地址能正常访问,但是无法从公网地址访问
    错误原因: 两次访问的端口不一致**
    解决方法:Nginx反向代理,将子域名转发到本地的5000端口

  4. 多次尝试后网站终于成功运行

4.总结与感悟

因课程需要尝试搭建网站,从查找教程到网站上线总共用了六天。网站源代码以及连接用的app.py均为AI生成。AI的功能确实非常强大,但仍会给出前后不一致的回答。通过多次追问能够解决这一问题。很难想象没有AI的帮助手敲网站代码需要多久,未来工作后大部分的代码应该都会由AI来实现,但是程序员仍然要熟悉代码的语法以便于改错。

Logo

openEuler 是由开放原子开源基金会孵化的全场景开源操作系统项目,面向数字基础设施四大核心场景(服务器、云计算、边缘计算、嵌入式),全面支持 ARM、x86、RISC-V、loongArch、PowerPC、SW-64 等多样性计算架构

更多推荐