how to string format when string have {

Mariano DAngelo marianoa.dangelo at gmail.com
Sun Apr 20 18:34:38 EDT 2014


I have the following string:

nginx_conf = '''
server {
    listen       80;
    server_name  dev.{project_url};

    location / {
        proxy_pass  http://127.0.0.1:8080;
        include     /etc/nginx/proxy.conf;
    }

    location /media  {
	alias /home/mariano/PycharmProjects/{project_name}/{project_name}/media;
        expires 30d;

    }
    location /static  {
	alias /home/mariano/PycharmProjects/{project_name}/{project_name}/static;
        expires 30d;
    }

    error_page   500 502  503 504  /50x.html;
    location =  /50x.html {
        root    html;
        }
}'''

And I want to format like this:

context = {
 "project_name":project_name,
 "project_url":project_url,
 }

nginx_conf.format(**context)


but since the string have { i can't.
Is there a way to solve this?



More information about the Python-list mailing list