|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
想要用pywebview+flask做一个小demo,代码如下:
- import flask
- import webview
- app = flask.Flask(__name__)
- @app.route('/')
- def home_page():
- return flask.render_template('index.html')
- @app.route('/admin/', methods=['GET', 'POST'])
- def hello_admin():
- if flask.request.form['password'] == '229773fxy':
- return "welcome, admin!"
- else:
- return "warning, wrong password, please check your password again"
- if __name__ == '__main__':
- window = webview.create_window(
- title='demo',
- url=app,
- confirm_close=True
- )
- cn = {
- 'global.quitConfirmation': u'确定关闭?'
- }
- webview.start(localization=cn, gui='mshtml')
复制代码
index.html内容如下:
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- </head>
- <body>
- <form action="http://127.0.0.1:5000/admin/" method="post">
- <p>Enter Password:</p>
- <input type="password" name="password" />
- <br>
- <input type="submit" value="done"/>
- </form>
- </body>
- </html>
复制代码
但当我按下“done”按钮后,显示无法访问此页面(也就是https://127.0.0.1:5000/admin/这个网址)
我自己的想法是,可能flask服务没有开启,所以无法访问
但如果在代码中加上app.run(__name__)时,主进程被阻塞,gui界面没有出现
我想使用multiprocessing把flask服务放到另一个进程运行,结果失败了:- Traceback (most recent call last):
- File "first_flask.py", line 22, in <module>
- Process(target=
- File "D:\anaconda3\lib\multiprocessing\process.py", line 121, in start
- self._popen = self._Popen(self)
- File "D:\anaconda3\lib\multiprocessing\context.py", line 224, in _Popen
- return _default_context.get_context().Process._Popen(process_obj)
- File "D:\anaconda3\lib\multiprocessing\context.py", line 327, in _Popen
- return Popen(process_obj)
- File "D:\anaconda3\lib\multiprocessing\popen_spawn_win32.py", line 93, in __init__
- reduction.dump(process_obj, to_child)
- File "D:\anaconda3\lib\multiprocessing\reduction.py", line 60, in dump
- ForkingPickler(file, protocol).dump(obj)
- TypeError: cannot pickle '_thread.lock' object
- (base) E:\coding file\MyPythonProjects\Flask\001test>Traceback (most recent call last):
- File "<string>", line 1, in <module>
- File "D:\anaconda3\lib\multiprocessing\spawn.py", line 116, in spawn_main
- exitcode = _main(fd, parent_sentinel)
- File "D:\anaconda3\lib\multiprocessing\spawn.py", line 126, in _main
- self = reduction.pickle.load(from_parent)
- EOFError: Ran out of input
复制代码
实在没办法,有没有人知不知道如何解决? |
|