English 中文(简体)
• 如何在Wxpython html窗口中插入动态插图? (wx.htmlwindow)
原标题:How to insert dynamic string in wxpython html window? (wx.html.htmlwindow)

I am making a html window in wxpython and want to print it. Before that I need to enter user input (such as his name or such things ) in the html page. How to do that nicely? Thanks in advance,

问题回答

rel=“nofollow noretinger”>Jinja2。

在需要显示用户输入数据的地方,建立具有变量的超文本模板。 然后,用含有该数据的字典来提供模板。

在此,我写给你一个助手模块。

# templates.py
import jinja2 as jinja

def create_env():
    loader = jinja.FileSystemLoader(PATH_TO_YOUR_TEMPLATES)
    env = jinja.Environment(loader=loader)
    return env

env = create_env()

def render(name, context=None):
    context = context or {}
    return env.get_template(name).render(context)

# my_module.py
import templates

data = {
     first_name :  John ,
     last_name :  Smith ,
}

html = templates.render( my_template.html , data)
# do something with html string

# my_template.html
<p>Hello, {{ first_name }} {{ last_name }}.  This is a template.</p>

我有两种办法。 如果它像一份仅取代特定部件的表格,那么,如果对使用者来说,你可以这样做,并且对用户有一些文字控制,以便填写。 与此类似:

Dear #NAME,

感谢您与NoCOMPANY、blah blah blah联系。

然后对每个可替换部分进行文本控制。 另一种方法是利用RichTextCtrl s Save As HTML功能。 See the wxPython Demo application for an example.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签