librelist archives

« back to archive

Re: [flask] Can't generate URLs testing Flask from the command

Re: [flask] Can't generate URLs testing Flask from the command

From:
Adam Hogan
Date:
2012-12-23 @ 06:30
The function that does the calling is in a view_helper.py file adjacent 
to my views.py folder, which holds all the app.routes.

Calling for the url builder, for url_for("profile", username=username) 
works in my templates, and it works in this very function while the 
application is running---just not when I run python from the command 
line to debug this function.

Maybe I'm getting an import statement wrong or out of order in my 
interactive python environment?

On 12/23/2012 01:25 AM, Shriram Kunchanapalli wrote:
>   line?
> MIME-Version: 1.0
> Content-Type: multipart/alternative;
> 	boundary="===============4883041006010031469=="
>
> --===============4883041006010031469==
> MIME-Version: 1.0
> Content-Type: text/plain; charset="utf-8"
> Content-Transfer-Encoding: 7bit
>
> How do you define the profile endpoint and route for it ?
> Could you briefly tell the structure of the app ?
> Where's the function that calls it located ( relative to other files) ?
>
> Sent from my Windows Phone
> From: Adam Hogan
> Sent: 23-12-2012 11:26
> To: flask@librelist.com
> Subject: [flask] Can't generate URLs testing Flask from the command
> line?
> Hi guys,
>
> I'm trying to test a function in the console before including it in my
> flask app.  So I've run python, and imported the views, models, and
> function files.
>
> However, when I try to run a function that calls url_for("profile",
> username=username), I get the following error:
>
> "RuntimeError: Attempted to generate a URL with the application context
> being pushed.  This has to be executed "
>
> Is it not possible to generate URLs, umm, out of context like this? If
> so, how would I accomplish this?  A google of this error message only
> returned links to this issue, #623, in the bug tracker:
> https://github.com/mitsuhiko/flask/issues/623
>
> Thanks!
> Adam
>
> --===============4883041006010031469==
> MIME-Version: 1.0
> Content-Type: text/html; charset="utf-8"
> Content-Transfer-Encoding: quoted-printable
>
> <html><head><meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Cont=
> ent-Type"></head><body><div><div style=3D"font-family: Calibri,sans-serif; =
> font-size: 11pt;">How do you define the profile endpoint and route for it ?=
> <br>Could you briefly tell the structure of the app ?<br>Where's the functi=
> on  that calls it located ( relative to other files) ?  <br><br>S=
> ent from my Windows Phone<br></div></div><hr><span style=3D"font-family: Ta=
> homa,sans-serif; font-size: 10pt; font-weight: bold;">From: </span><span st=
> yle=3D"font-family: Tahoma,sans-serif; font-size: 10pt;">Adam Hogan</span><=
> br><span style=3D"font-family: Tahoma,sans-serif; font-size: 10pt; font-wei=
> ght: bold;">Sent: </span><span style=3D"font-family: Tahoma,sans-serif; fon=
> t-size: 10pt;">23-12-2012 11:26</span><br><span style=3D"font-family: Tahom=
> a,sans-serif; font-size: 10pt; font-weight: bold;">To: </span><span style=
> =3D"font-family: Tahoma,sans-serif; font-size: 10pt;">flask@librelist.com</=
> span><br><span style=3D"font-family: Tahoma,sans-serif; font-size: 10pt; fo=
> nt-weight: bold;">Subject: </span><span style=3D"font-family: Tahoma,sans-s=
> erif; font-size: 10pt;">[flask] Can't generate URLs testing Flask from the =
> command line?</span><br><br></body></html><html>
>    <head>
>
>      <meta http-equiv=3D"content-type" content=3D"text/html; charset=3DISO-8=
> 859-1">
>    </head>
>    <body text=3D"#000000" bgcolor=3D"#FFFFFF">
>      Hi guys,<br>
>      <br>
>      I'm trying to test a function in the console before including it in
>      my flask app.  So I've run python, and imported the views, models,
>      and function files.<br>
>      <br>
>      However, when I try to run a function that calls url_for("profile",
>      username=3Dusername), I get the following error:<br>
>      <br>
>      "RuntimeError: Attempted to generate a URL with the application
>      context being pushed.  This has to be executed "<br>
>      <br>
>      Is it not possible to generate URLs, umm, out of context like this?&nbs=
> p;
>      If so, how would I accomplish this?  A google of this error messag=
> e
>      only returned links to this issue, #623, in the bug tracker:<br>
>      <meta http-equiv=3D"content-type" content=3D"text/html;
>        charset=3DISO-8859-1">
>      <a href=3D"https://github.com/mitsuhiko/flask/issues/623">https://githu=
> b.com/mitsuhiko/flask/issues/623</a><br>
>      <br>
>      Thanks!<br>
>      Adam<br>
>    </body>
> </html>
>
> --===============4883041006010031469==--