Skip to content

Commit 99a3af6

Browse files
committed
fix pywebio-battery demo import error
1 parent 1033be0 commit 99a3af6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

demos/doc_demo.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pywebio import start_server
99
from pywebio.platform import config
1010
from pywebio.session import local as session_local, info as session_info
11+
import pywebio_battery
1112

1213
##########################################
1314
# Pre-import modules for demo
@@ -30,7 +31,12 @@ def t(eng, chinese):
3031

3132

3233
def playground(code):
33-
code = f"{PRE_IMPORT}\n{code}"
34+
pre_import = PRE_IMPORT
35+
battery_apis = pywebio_battery.__all__
36+
if 'pywebio_battery import' not in code and any(api in code for api in battery_apis):
37+
pre_import += 'from pywebio_battery import *\n'
38+
39+
code = f"{pre_import}\n{code}"
3440
encode = base64.b64encode(code.encode('utf8')).decode('utf8')
3541
url = f"{playground_host}/#{encode}"
3642
run_js('window.open(url)', url=url)

0 commit comments

Comments
 (0)