librelist archives

« back to archive

Flask-Restful redirect

Flask-Restful redirect

From:
Leon Zhou
Date:
2013-03-12 @ 08:07
Hi all,
I am using flask-restful, how can I redirect or forward in backend? 

I try like this return redirect(location), it will not redirect like a 
browser behavior, return a 302 response in instead? Can I call method 
mapped by location and return result directly without second request?

Thanks,
Leon.Zhou

Re: [flask] Flask-Restful redirect

From:
Jeroen Pelgrims
Date:
2013-03-12 @ 08:38
That would involve loading the html of the url to redirect to page on your
server and sending that to the client.
e.g.: return urllib.urlopen(location).read() or something along those
lines. But that is definitely not desirable.
The displayed url in the browser will still be the one of the original
site. (since it in fact is still that site, it's just the result it returns
that's different)

On Tue, Mar 12, 2013 at 9:07 AM, Leon Zhou <leon.zhou@xplusz.com> wrote:

> Hi all,
> I am using flask-restful, how can I redirect or forward in backend?
>
> I try like this *return redirect(location), *it will not redirect like a
> browser behavior, return a 302 response in instead? Can I call method
> mapped by *location* and return result directly without second request?
>
> Thanks,
> Leon.Zhou
>

Re: [flask] Flask-Restful redirect

From:
Leon Zhou
Date:
2013-03-12 @ 09:42
Ya, ic. I will ask client site call twice.

Thanks,
Leon.Zhou

On Mar 12, 2013, at 4:38 PM, Jeroen Pelgrims <jeroen.pelgrims@gmail.com> wrote:

> That would involve loading the html of the url to redirect to page on 
your server and sending that to the client.
> e.g.: return urllib.urlopen(location).read() or something along those 
lines. But that is definitely not desirable.
> The displayed url in the browser will still be the one of the original 
site. (since it in fact is still that site, it's just the result it 
returns that's different)
> 
> On Tue, Mar 12, 2013 at 9:07 AM, Leon Zhou <leon.zhou@xplusz.com> wrote:
> Hi all,
> I am using flask-restful, how can I redirect or forward in backend? 
> 
> I try like this return redirect(location), it will not redirect like a 
browser behavior, return a 302 response in instead? Can I call method 
mapped by location and return result directly without second request?
> 
> Thanks,
> Leon.Zhou
> 

Re: [flask] Flask-Restful redirect

From:
paalzza
Date:
2013-03-12 @ 10:57
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    i while ago i asked about LocalStack usage (the question was - why
    stack and not just simple scalar?)<br>
    i've been given an answer that it can be used for performing local
    redirects (be somehow calling application twice, that will push
    second application to the stack)<br>
    i didn't investigate this further but you may want to try this
    approach<br>
    <br>
    <div class="moz-cite-prefix">12.03.2013 13:42, Leon Zhou 
пишет:<br>
    </div>
    <blockquote
      cite="mid:3B79BE6B-FB08-473C-9894-33D539613064@xplusz.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      <div>Ya, ic. I will ask client site call twice.</div>
      <div><br>
      </div>
      <div>Thanks,</div>
      <div>Leon.Zhou</div>
      <br>
      <div>
        <div>On Mar 12, 2013, at 4:38 PM, Jeroen Pelgrims <<a
            moz-do-not-send="true"
            
href="mailto:jeroen.pelgrims@gmail.com">jeroen.pelgrims@gmail.com</a>>
          wrote:</div>
        <br class="Apple-interchange-newline">
        <blockquote type="cite">
          <div>That would involve loading the html of the url to
            redirect to page on your server and sending that to the
            client. </div>
          <div>e.g.: return urllib.urlopen(location).read() or something
            along those lines. But that is definitely not desirable.</div>
          <div>The displayed url in the browser will still be the one of
            the original site. (since it in fact is still that site,
            it's just the result it returns that's different)</div>
          <br>
          <div class="gmail_quote">On Tue, Mar 12, 2013 at 9:07 AM, Leon
            Zhou <span dir="ltr"><<a moz-do-not-send="true"
                href="mailto:leon.zhou@xplusz.com" 
target="_blank">leon.zhou@xplusz.com</a>></span>
            wrote:<br>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <div style="word-wrap:break-word">Hi all,
                <div>I am using flask-restful, how can I redirect or
                  forward in backend? </div>
                <div><br>
                </div>
                <div>I try like this <b>return redirect(location), </b>it
                  will not redirect like a browser behavior, return a
                  302 response in instead? Can I call method mapped by 
<b>location</b>
                  and return result directly without second request?</div>
                <div><br>
                </div>
                <div>Thanks,</div>
                <div>Leon.Zhou</div>
              </div>
            </blockquote>
          </div>
          <br>
        </blockquote>
      </div>
      <br>
    </blockquote>
    <br>
  </body>
</html>

Re: [flask] Flask-Restful redirect

From:
Leon Zhou
Date:
2013-03-12 @ 12:04
Hi paalzza,
I cannot find your topic, can you give me your question link?

Thanks,
Leon.Zhoiu

On Mar 12, 2013, at 6:57 PM, paalzza <paalzza@gmail.com> wrote:

> <html>
>  <head>
>    <meta content="text/html; charset=ISO-8859-1"
>      http-equiv="Content-Type">
>  </head>
>  <body bgcolor="#FFFFFF" text="#000000">
>    i while ago i asked about LocalStack usage (the question was - why
>    stack and not just simple scalar?)<br>
>    i've been given an answer that it can be used for performing local
>    redirects (be somehow calling application twice, that will push
>    second application to the stack)<br>
>    i didn't investigate this further but you may want to try this
>    approach<br>
>    <br>
>    <div class="moz-cite-prefix">12.03.2013 13:42, Leon Zhou 
пишет:<br>
>    </div>
>    <blockquote
>      cite="mid:3B79BE6B-FB08-473C-9894-33D539613064@xplusz.com"
>      type="cite">
>      <meta http-equiv="Content-Type" content="text/html;
>        charset=ISO-8859-1">
>      <div>Ya, ic. I will ask client site call twice.</div>
>      <div><br>
>      </div>
>      <div>Thanks,</div>
>      <div>Leon.Zhou</div>
>      <br>
>      <div>
>        <div>On Mar 12, 2013, at 4:38 PM, Jeroen Pelgrims <<a
>            moz-do-not-send="true"
>            
href="mailto:jeroen.pelgrims@gmail.com">jeroen.pelgrims@gmail.com</a>>
>          wrote:</div>
>        <br class="Apple-interchange-newline">
>        <blockquote type="cite">
>          <div>That would involve loading the html of the url to
>            redirect to page on your server and sending that to the
>            client. </div>
>          <div>e.g.: return urllib.urlopen(location).read() or something
>            along those lines. But that is definitely not desirable.</div>
>          <div>The displayed url in the browser will still be the one of
>            the original site. (since it in fact is still that site,
>            it's just the result it returns that's different)</div>
>          <br>
>          <div class="gmail_quote">On Tue, Mar 12, 2013 at 9:07 AM, Leon
>            Zhou <span dir="ltr"><<a moz-do-not-send="true"
>                href="mailto:leon.zhou@xplusz.com" 
target="_blank">leon.zhou@xplusz.com</a>></span>
>            wrote:<br>
>            <blockquote class="gmail_quote" style="margin:0 0 0
>              .8ex;border-left:1px #ccc solid;padding-left:1ex">
>              <div style="word-wrap:break-word">Hi all,
>                <div>I am using flask-restful, how can I redirect or
>                  forward in backend? </div>
>                <div><br>
>                </div>
>                <div>I try like this <b>return redirect(location), </b>it
>                  will not redirect like a browser behavior, return a
>                  302 response in instead? Can I call method mapped by 
<b>location</b>
>                  and return result directly without second request?</div>
>                <div><br>
>                </div>
>                <div>Thanks,</div>
>                <div>Leon.Zhou</div>
>              </div>
>            </blockquote>
>          </div>
>          <br>
>        </blockquote>
>      </div>
>      <br>
>    </blockquote>
>    <br>
>  </body>
> </html>

Re: [flask] Flask-Restful redirect

From:
paalzza
Date:
2013-03-12 @ 12:28
subject was "question about flask internals"
discussion on March, 07-08
in the discussion there was a link to ronacher's talk about flask 0.9 
where he also mentions the possibility of "internal redirects" but 
without details

12.03.2013 16:04, Leon Zhou пишет:
> Hi paalzza,
> I cannot find your topic, can you give me your question link?
>
> Thanks,
> Leon.Zhoiu
>
> On Mar 12, 2013, at 6:57 PM, paalzza <paalzza@gmail.com> wrote:
>
>> <html>
>>   <head>
>>     <meta content="text/html; charset=ISO-8859-1"
>>       http-equiv="Content-Type">
>>   </head>
>>   <body bgcolor="#FFFFFF" text="#000000">
>>     i while ago i asked about LocalStack usage (the question was - why
>>     stack and not just simple scalar?)<br>
>>     i've been given an answer that it can be used for performing local
>>     redirects (be somehow calling application twice, that will push
>>     second application to the stack)<br>
>>     i didn't investigate this further but you may want to try this
>>     approach<br>
>>     <br>
>>     <div class="moz-cite-prefix">12.03.2013 13:42, Leon Zhou 
пишет:<br>
>>     </div>
>>     <blockquote
>>       cite="mid:3B79BE6B-FB08-473C-9894-33D539613064@xplusz.com"
>>       type="cite">
>>       <meta http-equiv="Content-Type" content="text/html;
>>         charset=ISO-8859-1">
>>       <div>Ya, ic. I will ask client site call twice.</div>
>>       <div><br>
>>       </div>
>>       <div>Thanks,</div>
>>       <div>Leon.Zhou</div>
>>       <br>
>>       <div>
>>         <div>On Mar 12, 2013, at 4:38 PM, Jeroen Pelgrims <<a
>>             moz-do-not-send="true"
>>             
href="mailto:jeroen.pelgrims@gmail.com">jeroen.pelgrims@gmail.com</a>>
>>           wrote:</div>
>>         <br class="Apple-interchange-newline">
>>         <blockquote type="cite">
>>           <div>That would involve loading the html of the url to
>>             redirect to page on your server and sending that to the
>>             client. </div>
>>           <div>e.g.: return urllib.urlopen(location).read() or something
>>             along those lines. But that is definitely not desirable.</div>
>>           <div>The displayed url in the browser will still be the one of
>>             the original site. (since it in fact is still that site,
>>             it's just the result it returns that's different)</div>
>>           <br>
>>           <div class="gmail_quote">On Tue, Mar 12, 2013 at 9:07 AM, Leon
>>             Zhou <span dir="ltr"><<a moz-do-not-send="true"
>>                 href="mailto:leon.zhou@xplusz.com" 
target="_blank">leon.zhou@xplusz.com</a>></span>
>>             wrote:<br>
>>             <blockquote class="gmail_quote" style="margin:0 0 0
>>               .8ex;border-left:1px #ccc solid;padding-left:1ex">
>>               <div style="word-wrap:break-word">Hi all,
>>                 <div>I am using flask-restful, how can I redirect or
>>                   forward in backend? </div>
>>                 <div><br>
>>                 </div>
>>                 <div>I try like this <b>return redirect(location), </b>it
>>                   will not redirect like a browser behavior, return a
>>                   302 response in instead? Can I call method mapped by 
<b>location</b>
>>                   and return result directly without second request?</div>
>>                 <div><br>
>>                 </div>
>>                 <div>Thanks,</div>
>>                 <div>Leon.Zhou</div>
>>               </div>
>>             </blockquote>
>>           </div>
>>           <br>
>>         </blockquote>
>>       </div>
>>       <br>
>>     </blockquote>
>>     <br>
>>   </body>
>> </html>
>