Skip to content

Commit

Permalink
fix pywebio-battery demo import error
Browse files Browse the repository at this point in the history
  • Loading branch information
wang0618 committed Jan 5, 2023
1 parent 1033be0 commit 99a3af6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion demos/doc_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pywebio import start_server
from pywebio.platform import config
from pywebio.session import local as session_local, info as session_info
import pywebio_battery

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


def playground(code):
code = f"{PRE_IMPORT}\n{code}"
pre_import = PRE_IMPORT
battery_apis = pywebio_battery.__all__
if 'pywebio_battery import' not in code and any(api in code for api in battery_apis):
pre_import += 'from pywebio_battery import *\n'

code = f"{pre_import}\n{code}"
encode = base64.b64encode(code.encode('utf8')).decode('utf8')
url = f"{playground_host}/#{encode}"
run_js('window.open(url)', url=url)
Expand Down

0 comments on commit 99a3af6

Please sign in to comment.