如何在Python粘贴部署配置文件中转义百分比字符?

如何在Python粘贴部署配置文件中转义百分比字符?,python,python-paste,Python,Python Paste,我已经使用Python粘贴部署脚本部署了一个Flask+Gunicorn项目。但是,我无法使用hs%ls%us%ts%rs%ss%bs%f在部署脚本中写入访问日志格式。因为我们%hs格式在粘贴部署脚本中有特殊意义。如文件所述: You can use variable substitution, which will pull variables from the section [DEFAULT] (case sensitive!) with markers like % (var_name

我已经使用Python粘贴部署脚本部署了一个Flask+Gunicorn项目。但是,我无法使用hs%ls%us%ts%rs%ss%bs%f在部署脚本中写入访问日志格式。因为我们%hs格式在粘贴部署脚本中有特殊意义。如文件所述:

You can use variable substitution, which will pull variables from 
the section [DEFAULT] (case sensitive!) with markers like %
(var_name)s. The special variable %(here)s is the directory
containing the configuration file;

但是,我可以绕过这个问题吗?

在本例中,您尝试配置应用程序的两个组件—Gunicorn和正在使用Paste Deploy的Flask应用程序。Gunicorn负责访问日志记录,而Flask/Paste Deploy则使用现有配置进行配置。Paste Deploy负责在其自己的配置文件中替换神奇的变量,这与Gunicorn访问日志配置冲突

您可以为Gunicorn提供单独的配置文件,该文件将包含您的访问日志格式。例如:

gunicorn-c gunicorn.conf-paste demo.conf

gunicorn.conf:


你试过用引号把字符串括起来吗?e、 g.access_log_format='%hs'能否将access_log_format字段移到[默认]之外的某个节中?该措辞暗示变量替换仅在该配置部分起作用。在我自己的Pyramid应用程序中,日志记录配置看起来很像@IanMarcinkowski中的示例。不,我将其放在[server:main]部分,而不是[DEFAULT]部分。不,它不能在粘贴部署中工作。类似这样的内容将成为错误消息。错误:文件demo.conf中出错:错误值替换:节:[server:main]选项:access\u log\u format键:h rawval:%hs您想过在命令行上传递访问日志格式吗?我没有看到任何兼容的方式通过粘贴格式的配置文件向Gunicorn提供访问日志格式。您是否使用gunicorn或pserve从命令行运行应用程序?您可以创建2个配置文件;一个用于Gunicorn,另一个用于烧瓶应用。您试图配置的访问日志是Gunicorn的一部分,而不是Flask应用程序。试试这样:gunicorn-c gunicorn.conf-paste application.conf[…]@IanMarchinkowski,这对我来说很好。我要试一试。我终于用命令行中指定的access日志格式参数尝试了这个方法。太好了!我会更新我的答案。如果你还有什么麻烦,请告诉我。
accesslog = access.log
access_log_format = %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"