Python Forum

Full Version: python Render template
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I've created a template using python, but now I need to generate a .qml file from it, I wanted to work with rendered template but I coudn't go any where Wall
this is my example :

import string
v={'var1':'screen'}
x=string.Template("""
{
id :$var1
width :22
height :123
""")
print'Item: ', x.substitute(v)
y="""
{
id :$sm1
x :11
y :8
width :12
height :65

}
}

"""
print 'Rectangle ' , y%v

I really need your help!
thank u ^^
Please put your code in Python code tags, you can find help here.

What have you tried so far? What was the result, did you get errors or wrong format?
this is my code
    # -*- coding: utf-8 -*-
    """
    Created on Thu Apr 26 20:55:49 2018

    @author: Akhou
    """

    import string 
    v={'var1':'screen'}
    x=string.Template("""
    {
    id      :$var1
    width   :22
    height  :123
    """)
    print'Item: ', x.substitute(v)
    y="""
    {
    id      :$sm1
    x       :11
    y       :8
    width   :12
    height  :65
    } 
    """
    print 'Rectangle ' , y%v
now I want to generate a .qml file from it. So I looked on line for an example to follow( atleast to understand the concept) I found that rebder template is able to generate/create a .qml file. I tried this example ( just to understand how it (rendered_teplate) work :
    from flask import Flask, render_template
    from flask import request, jsonify
    app = Flask(__name__)
    @app.route('/', methods=['GET', 'POST'])
    def homepage():
       if request.method == 'POST':
           f1 = request.form['firstVerb'] 
           f2 = request.form['secondVerb']
       return render_template('index.html', f1=f1, f2=f2)

    if __name__ == "__main__":
        app.run(debug=True) 
All I got was that text :
Error:
* Restarting with stat