pc.redirect not work
Describe the bug A component defiend as following and given to app.add_custom_404_page(page_not_found):
def page_not_found() -> pc.Component: return pc.redirect("/")
get such an error: page.children.append( ^^^^^^^^^^^^^ AttributeError: 'EventSpec' object has no attribute 'children'
To Reproduce Steps to reproduce the behavior:
- Code/Link to Repo:
Expected behavior A clear and concise description of what you expected to happen.
Screenshots If applicable, add screenshots to help explain your problem.
** Specifics (please complete the following information):**
- Python Version:
- Pynecone Version:
- OS:
- Browser (Optional):
Additional context Add any other context about the problem here.
pc.redirect is an event (as denoted by the EventSpec type that is returned by your page_not_found() method.
It's normal your code does not work.
What you want to do is to use an empty page with an on_load method that does the redirect:
app.custom_404_page(pc.fragment(), on_load=pc.redirect("/"))
@Lendemor I don't see an on_load method of app.custom_404_page.
def add_custom_404_page(
self,
component,
title=None,
image=None,
description=None,
meta=constants.DEFAULT_META_LIST,
):
I literally don't know anything about pynecone except it's a pure python solution for web pages but note that is custom_404_page not add_custom_404_page, you can check it with this two ways:
...
import inspect
print(inspect.getsource(app.custom_404_page))
It will show the source code of the function, also you can do this:
...
import code
code.interact(local=locals())
>>> help(app.custom_404_page)
It opens an interactive session and call help() with the function.