python数据怎么传递给html_将变量传递给Python上的html文件(Passing variables to html file on Python)...

本文探讨了如何在不使用模板引擎的情况下,使用CherryPy微框架将Python变量传递给HTML文件。通过在HTML文件中使用格式化字符串,并在Python代码中调用`format()`方法,可以实现变量的传递。
摘要由CSDN通过智能技术生成

将变量传递给Python上的html文件(Passing variables to html file on Python)

我正在使用以下函数来执行简单的HTML视图:

import cherrypy

class index(object):

@cherrypy.expose

def example(self):

var = "goodbye"

index = open("index.html").read()

return index

我们的index.html文件是:

Hello, {var}!

如何将{var}变量从控制器传递给视图?

我正在使用CherryPy微框架来运行HTTP服务器而我没有使用任何模板引擎。

I'm using the following function to execute a simple HTML view:

import cherrypy

class index(object):

@cherrypy.expose

def example(self):

var = "goodbye"

index = open("index.html").read()

return index

Our index.html file is:

Hello, {var}!

How can I pass the {var} variable to the view from my controller?

I'm using CherryPy microframework to run

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值