how to string format when string have {

Tim Chase python.list at tim.thechases.com
Sun Apr 20 19:43:44 EDT 2014


On 2014-04-20 15:34, Mariano DAngelo wrote:
> I have the following string:
... 
> but since the string have { i can't.
> Is there a way to solve this?

I second Chris Angelico's suggestion about using the older percent
formatting:

nginx_conf = '''
server {
    listen       80;
    server_name  dev.%(project_url)s;
    location / {
        proxy_pass  http://127.0.0.1:8080;
        include     /etc/nginx/proxy.conf;
    }
    location /media  {
	alias /home/mariano/PycharmProjects/%(project_name)s/%(project_name)s/media;
        expires 30d;
    }
    location /static  {
	alias /home/mariano/PycharmProjects/%(project_name)s/%(project_name)s/static;
        expires 30d;
    }
    error_page   500 502  503 504  /50x.html;
    location =  /50x.html {
        root    html;
        }
}'''
context = {
 "project_name":project_name,
 "project_url":project_url,
 }

print(nginx_conf % context)

-tkc







More information about the Python-list mailing list