用途:把静态 HTML/CSS 网站部署到 ERPNext/Frappe v15/v16,通过 REST API 创建与管理 Web Page,并配置站点导航与讨论功能。
关键限制:Frappe v16 不渲染 Web Page 的 main_section 字段,即使设置 content_type 为 HTML 或 dynamic_template=1 也无效,必须改用 Page Builder(page_blocks)配合自定义 Web Template 渲染 HTML。
主要步骤:一、一次性创建名为 Raw HTML Section 的 Web Template,type 为 Section,template 为 {{ values.html_content }};字段 fieldtype 必须为 Text,Frappe 不接受 Code,可用类型包括 Attach Image、Check、Data、Int、Link、Select、Small Text、Text、Markdown Editor、Section Break、Column Break、Table Break。二、创建 Web Page,设置 content_type 为 Page Builder,HTML 放入 page_blocks;web_template_values 必须是 JSON 字符串(用 json.dumps() 序列化)而非对象;更新用 PUT /api/resource/Web%20Page/{url_encoded_name},按 route 查找用 GET 配合 filters。三、配置 Website Settings,包括 home_page、brand_html、head_html、top_bar_items、footer_items。
CSS 管理:页面样式写在 Web Page 的 css 字段,Google Fonts、CSS 变量与 Frappe 包装元素修复写在 Website Settings 的 head_html。仅在 head_html 中对 Frappe 自身包装元素使用 !important 覆盖,不要对内容元素(如 .card、section、h2)做宽泛覆盖。
从 HTML 原型部署:提取主内容区(通常在 </header> 与 <footer> 之间),移除原型自带的导航与页脚;把 .html 链接改写为 Frappe 路由(如 about.html→/about,index.html→/);本地 img/ 路径不可用,需上传到 Frappe 文件管理器或使用外部绝对 URL。
论坛集成:可用内置 Discussion Topic、Discussion Reply DocType 与 Discussions Web Template,字段含 title、cta_title、docname、single_thread。
认证:所有 API 调用需 token 头 Authorization: token {api_key}:{api_secret},密钥在 User Settings → API Access 生成,不得写入技能文件或提交到 git,应使用环境变量或安全配置。资料未提供收费、价格等其它信息。