custom-route can't be found.
- Python Version: 3.9
- Pynecone Version: latest
- OS: windows 10
- Browser (Optional): edge
About page and Index page is ok, but when I try to custom-route give me this message: Invariant: attempted to hard navigate to the same URL /custom-route http://localhost:3000/custom-route
This is my main code:
def about(): return pc.text("About page")
def custom(): return pc.text("custom")
app = pc.App(state=State) app.add_page(index) app.add_page(about) app.add_page(custom, path="/custom-route") app.compile()
I don't kown why, this is just a example in docs.
Ok that's odd I just tried an example using that path and it seemed to work for me. Anyone else getting this issue?
\lib\site-packages\pynecone\compiler\utils.py line 305, in write_page with open(path, "w") as f: PermissionError: [Errno 13] Permission denied: '/custom-route.js'
Can you post your whole python file, thanks.
"""Welcome to Pynecone! This file outlines the steps to create a basic app."""
from pcconfig import config
import pynecone as pc
docs_url = "https://pynecone.io/docs/getting-started/introduction"
filename = f"{config.app_name}/{config.app_name}.py"
class State(pc.State):
"""The app state."""
pass
def index():
return pc.center(
pc.vstack(
pc.heading("Welcome to Pynecone!", font_size="2em"),
pc.box("Get started by editing ", pc.code(filename, font_size="1em")),
pc.link(
"Check out our docs!",
href=docs_url,
border="0.1em solid",
padding="0.5em",
border_radius="0.5em",
_hover={
"color": "rgb(107,99,246)",
},
),
spacing="1.5em",
font_size="2em",
),
padding_top="10%",
)
def about():
return pc.text("About page")
def custom():
return pc.text("custom")
def test():
return pc.text("ok")
app = pc.App(state=State)
app.add_page(index)
app.add_page(about)
app.add_page(test)
app.add_page(custom,path="/custom-route")
app.compile()
I tried this and it worked fine for me.
"""Welcome to Pynecone! This file create a counter app."""
import pynecone as pc
class State(pc.State):
pass
def index():
return pc.text("Example")
def about():
return pc.text("About page")
def custom():
return pc.text("custom")
app = pc.App(state=State)
app.add_page(index)
app.add_page(about)
app.add_page(custom, path="/custom-route")
app.compile()
Your file worked for me as-well, that's odd. Maybe a windows error I'm on Mac if any other users get this error I'll take a deeper look
Just an idea but maybe Windows doesn't like that the file created start with a /
Try
app.add_page(custom, path="custom-route")
Instead
Thanks, good suggestion @Lendemor this seems to work as seen on discord. We will fix this so the "/" way works aswell in the next release
Thanks, good suggestion @Lendemor this seems to work as seen on discord. We will fix this so the "/" way works aswell in the next release
Okay, I'll wait the time the problem is resolved.
\lib\site-packages\pynecone\compiler\utils.py line 305, in write_page with open(path, "w") as f: PermissionError: [Errno 13] Permission denied: '/custom-route.js'
I've the same issue in Windows, because the script tries to write to the home path C:\ where admin privileges are required, as a temporary workaround run the script as admin.
I've the same issue in Windows, because the script tries to write to the home path
C:\where admin privileges are required, as a temporary workaround run the script as admin.
I have tried running as administrator but it didn't work for me.
Ok got it thanks for pointing this out we are on Mac so these bugs can be hard to find. We can look into a fix, if any of you know an easy fix on windows lmk
I don't want to be wrong but I think it is due to how the file system handles paths, on Linux & Mac it should work, while on Windows it doesn't. Maybe some form of escaping is needed. I will try to take a look at it as soon as possible and try to solve it.
- Python Version: 3.9
- Pynecone Version: latest
- OS: windows 10
- Browser (Optional): edge
About page and Index page is ok, but when I try to custom-route give me this message: Invariant: attempted to hard navigate to the same URL /custom-route http://localhost:3000/custom-route
This is my main code:
def about(): return pc.text("About page")
def custom(): return pc.text("custom")
app = pc.App(state=State) app.add_page(index) app.add_page(about) app.add_page(custom, path="/custom-route") app.compile()
I don't kown why, this is just a example in docs.
Figured it out: When using Pynecone on Windows, it's using NPM and JavaScript so you have to specify the path as "./custom-route" rather than the python version: "/custom-route"
Awesome we will automatically format the path correctly as a fix