帮助、资源和提示
We've done our best to make PY4WEB simple and clean. But you know, modern web programming is a daunting task. It requires an open mind, able to jump frequently (without being lost!) from python to HTML to javascript to css and even database management. But don't be scared, in this manual we'll assist you side by side in this journey. And there are many other valuable resources that we're going to show you.
资源
本手册
This manual is the Reference Manual for py4web. It's available online at https://py4web.com/_documentation/static/index.html, where you'll also find the PDF and EBOOK version, in multiple languages. It is written in RestructuredText and generated using Sphinx.
Google group(中国大陆无法访问)
有一个专属的邮件列表托管在 Google Groups 上,访问链接:https://groups.google.com/g/py4web。这是开发者和普通用户讨论的主要渠道。遇到任何问题,这是寻找提示或解决方案的合适去处。
Discord server(中国大陆无法访问)
如需快速问答或交流,您还可以使用专为 py4web 设立的免费的 Discord server dedicated to py4web 。通常可以在该频道看到许多 py4web 开发者在线互动。
教程和视频
有许多教程和视频可供选择。以下是其中一些:
由 Luca de Alfaro 建立的网站 Learn py4web (里面有很多优秀的培训视频)
UC Santa Cruz 上的免费视频资源 course 2020 by Luca de Alfaro (中国大陆无法访问)
Andrew Gavgavian 制作的 py4web blog app 它使用 py4web 复制了著名的 Corey Schafer 的关于在 Django 中创建博客应用程序的系列教程(中国大陆无法访问)
由 Jim Steil 建立的演示应用程序 South Breeze Enterprises 。它是围绕 Microsoft Northwind 数据库的结构构建的,但已转换为 SQLite。您可以在 这里 在线查看最终结果
the py4web blog in spanish by Alan Etkin, which covers the basics to start with the framework plus examples. It is intended as a resource for students and aims to provide a full web development course
GitHub 上的资源
最后但同样重要的是,py4web 是开源的,具有 BSD v3 许可证,托管在 GitHub 上 https://github.com/web2py/py4web。这意味着你可以自己阅读、研究和实验它的所有内部细节。
提示和技巧
在开始学习 py4web 之前,本节专门用来介绍一些有有用的提示、建议和技巧。
先决条件
为了理解 py4web ,你至少需要一些基本的 python 知识。网络上有许多书籍、课程和教程可供选择——选择最适合你的。特别是 python 的装饰器(decorator),是理解任何 python web 框架的里程碑(重要概念),你必须完全理解它。
一个现代化的 Python 工作环境
在接下来的章节中,您将开始在计算机上编码。如果你打算高效安全地使用 python,我们建议你安装一个现代化的 python 工作环境。即使是运行简单的示例和进行小实验,我们也强烈建议使用集成开发环境(IDE)。这将使您的编程体验更好,允许语法检查、链接 和可视化调试。如今,主要有两种免费和多平台的选择:微软开发的 Visual Studio Code(又名 VS Code )和 JetBrains 开发的 PyCharm 。
当您要开始处理更复杂的程序并需要可靠性时,我们还建议:
使用虚拟环境(也称为 virtualenv ,请参阅 这里 了解介绍)。在复杂的工作环境中,这将避免与其他 python 程序和模块混淆。
use git to keep track of your program's changes and save your changes in a safe place online (GitHub, GitLab, or Bitbucket).
使用带语法高亮的编辑器,我们强烈推荐 Visual Studio Code (VS Code) 或 PyCharm。
用 VS Code 调试 py4web 开发的应用
在 VS Code 中运行和调试 py4web 开发的应用非常简单。
如果你已经从源代码安装了 py4web,你只需要用 VS Code 打开 py4web 的主文件夹(不是 apps 文件夹!)并以下配置添加到 VS Code 的 launch.json 配置文件中 :
"args": ["run", "apps"],
"program": "your_full_path_to_py4web.py",
请注意,如果您使用的是 Windows,则 “your_full_path_to_py4web.py” 参数必须仅使用正斜杠编写,如 “C:/Users/your_name/py4web/py4web.py”
如果你已经从 pip 安装了 py4web ,你需要在将 launch.json 文件里设置为将 py4web 作为模块运行
{
"name": "py4web apps",
"type": "debugpy",
"request": "launch",
"module": "py4web",
"args": ["run", "apps", "-D", "--watch", "lazy"]
}
调整 args 以匹配您的应用文件夹。例如,如果你在 VS Code 中打开 apps 文件夹本身,就将 apps 替换为 . 。
小技巧
在这两种情况下,如果你得到 gevent 错误,你还必须在 launch.json 配置文件中添加 "gevent": true 。
使用 PyCharm 调试 py4web
在 PyCharm 中,若遇到 gevent 相关错误,需启用 “Settings | Build, Execution, Deployment | Python Debugger | Gevent compatible”(即 “设置 | 构建、执行、部署 | Python 调试器 | 兼容 Gevent” )选项。
如何贡献
We need help from everyone: support our efforts! You can just participate in the Google group trying to answer others' questions, submit bugs or create pull requests on the GitHub repository.
如果您想更正和扩展本手册,甚至将其翻译成新的外语,您可以直接在 GitHub 上的 specific README 上阅读所有需要的信息。
这真的很简单!只要换一下在 /doc 文件夹中的 .RST 文件,并在 GitHub 存储库上 https://github.com/web2py/py4web 创建 Pull 请求 -- 你甚至可以在浏览器中完成。一旦 PR 被接受,您的更改将写入主分支,并在分支的下一代输出中反映在网页 /pdf/epub 上。