Comments (7)
BTW, in this part of documentation, the first part is named
task 1, task 2
but the example is A and B.
from pywebio.
Multiple routes app
The start_server()
and path_deploy()
both support multiple app.
start_server()
accepts a list of task function or a dictionary of task function, and path_deploy()
can route the PyWebIO applications by request path.
If you want to blind multiple app to your Flask project, you can use the follow code:
from pywebio.platform.flask import webio_view
from flask import Flask
app = Flask(__name__)
# `task_func` is PyWebIO task function
app.add_url_rule('/tool', 'webio_view', webio_view(task_func), methods=['GET', 'POST', 'OPTIONS'])
app.add_url_rule('/tool2', 'webio_view', webio_view(task_func2), methods=['GET', 'POST', 'OPTIONS'])
app.run(host='localhost', port=80)
Also, webio_view()
accepts a list of task function or a dictionary of task function:
from pywebio.platform.flask import webio_view
from flask import Flask
app = Flask(__name__)
app.add_url_rule('/tool', 'webio_view', webio_view([task_func, task_func2]), methods=['GET', 'POST', 'OPTIONS'])
app.run(host='localhost', port=80)
When pass multiple task functions to webio_view()
, you need use app
url parameter to route the app. e.g. using http://host:port/tool?app=task_func2
to access task_func2
app.
from pywebio.
BTW, in this part of documentation, the first part is namedtask 1, task 2
but the example is A and B.
Two ways to start server mode is introduced in that part of documentation. The first example is about start_server()
, and the second is the usage of path_deploy()
from pywebio.
@wang0618 Thank you for the detailed answer.
I do believe that the Pywebio has the potential to become greater than Streamlit and Plotly Dash.
It has the simplicity of Streamlit and functionality of Dash.
I ,as a medical student, will do my best, to give the credit of my projects to PyWebIO and make it even more famous in German speaking world.
Keep doing support.
Best.
from pywebio.
File "", line 27, in
File "/home/PATH/python3.8/site-packages/flask/app.py", line 98, in wrapper_func
┊ return f(self, *args, **kwargs)
File "/home/PATHlib/python3.8/site-packages/flask/app.py", line 1282, in add_url_rule
┊ raise AssertionError(
AssertionError: View function mapping is overwriting an existing endpoint function: webio_view
Here is the error which I got.
from pywebio.platform.flask import webio_view
from pywebio import STATIC_PATH
from flask import Flask, send_from_directory
from pywebio.input import input, FLOAT
from pywebio.output import put_text
app = Flask(__name__)
def bmi():
height = input("your height in cm: ",type = FLOAT)
weight = input("your weight in kg : ", type = FLOAT)
def mba():
Height2 = input ("22222 in cm", type = FLOAT)
Weight2 = input("3333333: ", type = FLOAT)
app.add_url_rule('/home', 'webio_view', webio_view(bmi), methods=['GET', 'POST', 'OPTIONS'])
app.add_url_rule('/home2', 'webio_view', webio_view(mba), methods=['GET', 'POST', 'OPTIONS'])
app.run(host='localhost', port=5000)
here is the code!
simple but does not work!
from pywebio.
Oops! Forgot to change the second parameter of app.add_url_rule
, you need a different name in app.add_url_rule
:
app.add_url_rule('/home', 'webio_view1', webio_view(bmi), methods=['GET', 'POST', 'OPTIONS'])
app.add_url_rule('/home2', 'webio_view2', webio_view(mba), methods=['GET', 'POST', 'OPTIONS'])
See also: https://flask.palletsprojects.com/en/1.1.x/api/#flask.Flask.add_url_rule
from pywebio.
Works smoothly and without any problems.
End of the issue.
Thanks.
from pywebio.
Related Issues (20)
- 表单点击提交后没有发送请求 HOT 6
- ERROR:pywebio.platform.remote_access HOT 2
- put_table can not set style, override via css or anything else HOT 3
- [Feature Request] HOT 1
- 当使用手机浏览器访问pywebio生成的网页时,put_audio无法自动播放
- put_file_upload 问题 1.8.2version HOT 1
- Side margins are very large, space is wasted HOT 2
- [Feature Request] remove scope HOT 2
- [Feature Request]put_tabs HOT 1
- [Feature Request]Horizontal Tabs
- [Feature Request]Update popup content
- input_group action cancelable 表现错误 HOT 2
- Page not get inactive if there are buttons in the page HOT 2
- 使用put_file_upload时跳出的展示上传进度的toast中显示的百分比数字范围在0~1 HOT 1
- 渲染列表初始正常,后续渲染倒序 HOT 3
- 在 'pywebio.py' 中找不到引用 'input' HOT 2
- 关于put_datatable建立复杂的**式报表问题 HOT 1
- 静态资源托管不是所有资源都生效 HOT 5
- 如何修改网页图标 HOT 1
- In version 1.8 put_loading not work any more. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pywebio.