Robyn
Robyn copied to clipboard
View controllers don't have access to the global variables.
Bug Description
Try creating a view and then accessing a global variable through that. It doesn't work.
Something like this doesn't work. Fix this.
db = DB()
def AsyncView():
async def get():
res = db(bla)
return "Hello, world!"
Steps to Reproduce
No response
Your operating system
None
Your Python version (python --version
)
None
Your Robyn version
None
Additional Info
No response
Does this have any news? I am really interested in working with Views. Any idea if making the Instance on the View does make it work?
@Noborita9 , apologies for the late revert. This comment missed my eye.
Any idea if making the Instance on the View does make it work?
What do you mean by this?
He probably means to create "db" from inside the view. But it doesn’t work either.
And functions that are not named by methods will raise an error iirc. Something along a wrong index value when nested functions are being collected.
Perhaps it can be implemented with a decorator like @view_extension that can pass functions other than method handlers. These functions can carry globales and return them to method handlers or something like that.
He probably means to create "db" from inside the view. But it doesn’t work either.
Yeah exactly that
I don't think that will work. I am using this library for this - https://github.com/sansyrox/nestd/blob/main/nestd/init.py#L35
We will have to change something around this line imo.
Yes, that’s where it throw the error. I have had no time to investigate further. :(
No worries. I will get around to it soon 😄