Hi,
having used flask a bit I was wondering what the best way in picoweb was to redirect from one route to another.
Let's say I'm using a certain GET method on route '/switch' to toggle a pin and I want to return to '/index' after that.
Thanks,
/Matthias
picoweb redirect
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: picoweb redirect
Have you looked at this webserver for micro-python it is what I use for my projects https://github.com/jczic/MicroWebSrv
Here's a YouTube video made by a user on this forum https://www.youtube.com/watch?v=xscBwC1SrF4
Here's a YouTube video made by a user on this forum https://www.youtube.com/watch?v=xscBwC1SrF4
Re: picoweb redirect
picoweb is just a thin layer on top of HTTP. So the way to redirect in picoweb is the same as in HTTP. Just use your knowledge of how to do HTTP redirects, voila. As for the best way - well, everyone has their own best way, and it usually differs on a case by case basis.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Re: picoweb redirect
OK, thanks guys.
Here's what I've ended up using:
Here's what I've ended up using:
Code: Select all
@app.route('/some_url')
def some_url(req, resp):
...
(GET/POST parameter handling)
...
# redirect to "/"
headers = {"Location": "/"}
yield from picoweb.start_response(resp, status="303", headers=headers)
Re: picoweb redirect
Righto. Can optimize it beyond that (or not - that's the power of picoweb: it gives a choice whether to optimize even such minor things, or forget about it and go pretty high-level). I'll consider adding a builtin func for that, thanks for ping. But the point is that you don't need to depend on that - you can do anything yourself, and picoweb is intended to stay minimal (and thus run on devices like esp8266 or even smaller!). Any (considerable) extension is supposed to come in the form of external modules/plugins (and that's not a surprise - Flask, the picoweb's inspiration, works in the same way).
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/