Coder Social home page Coder Social logo

multiple routes about pywebio HOT 7 CLOSED

pywebio avatar pywebio commented on June 14, 2024
multiple routes

from pywebio.

Comments (7)

Shahin-rmz avatar Shahin-rmz commented on June 14, 2024 1

image
BTW, in this part of documentation, the first part is named

task 1, task 2

but the example is A and B.

from pywebio.

wang0618 avatar wang0618 commented on June 14, 2024

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.

wang0618 avatar wang0618 commented on June 14, 2024

image
BTW, in this part of documentation, the first part is named

task 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.

Shahin-rmz avatar Shahin-rmz commented on June 14, 2024

@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.

Shahin-rmz avatar Shahin-rmz commented on June 14, 2024

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.

wang0618 avatar wang0618 commented on June 14, 2024

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.

Shahin-rmz avatar Shahin-rmz commented on June 14, 2024

Works smoothly and without any problems.
End of the issue.
Thanks.

from pywebio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.