web2py 与每个环境的配置

发布于 2024-11-10 16:35:42 字数 99 浏览 2 评论 0原文

web2py 是否支持按环境(开发、登台、生产等)进行开箱即用的配置?类似于 Grails 和 Ruby on Rails。

我阅读/浏览了官方书籍,但找不到任何内容。

Does web2py support, out of the box, configuration per environment (development, staging, production, etc.)? Something similar to Grails and Ruby on Rails.

I read/skimmed through official book but could not find anything.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谈下烟灰 2024-11-17 16:35:42

web2py 开发人员认为这不是一个好方法。

我们不相信开发和生产之间有明显的区别。
例如,如果应用程序存在错误,则该错误始终会被记录和记录,从不向用户显示,仅向管理员显示。

此外,web2py 根本没有配置文件,因为应用程序应该是可移植的,而不会破坏设置。

然而,您可以以比 Rails 或 Django 允许的更复杂的方式管理不同的环境。这是因为模型不是导入的,而是根据每个请求执行的。您可以添加自己的条件来在运行时检测环境。例如:

  settings = dict()
  if request.env.http_host == 'http://127.0.0.1:8000'
       settings['development']=True
  else:
       settings['development']=False
  if settings['development']:
       db = DAL('sqlite://....')
  else:
       db = DAL('mysql://....')

您可以了解如何将其推广到更复杂的条件。当然,您可以将 settings['development']=True 或 False 设置为常量,这与 Rails 等效。

The web2py developers do not believe that is a good approach.

We do not believe in the sharp distinction between development and production.
For eaxmple, if an app has a bug, the bug is always recorded and logged, never shown to the user, only shown to the administrator.

Moreover web2py does not have a configuration file at all because apps should be portable without mangling with settings.

Yet you can manage different environments and in a more sophisticated way than Rails or Django allows. That is because models are not imported but executed at every request. You add your own conditions to detect the environment at runtime. For example:

  settings = dict()
  if request.env.http_host == 'http://127.0.0.1:8000'
       settings['development']=True
  else:
       settings['development']=False
  if settings['development']:
       db = DAL('sqlite://....')
  else:
       db = DAL('mysql://....')

You can see how to generalize this to more complex conditions. Of course you can make settings['development']=True or False constant, which is the Rails equivalent way of doing it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文