librelist archives

« back to archive

question about flask internals

question about flask internals

From:
paalzza
Date:
2013-03-08 @ 17:00
hi all

why do we use stack (not just simple scalar) for request and application 
contexts?
in what situation could there be more than one element in these stacks?

Re: [flask] question about flask internals

From:
Jose Ayerdis
Date:
2013-03-08 @ 17:05
Because Flask does not assume that is a single application that one that
will be running therefore you need to stack them. This is more obvious
whenever you are builting a plugin.

http://www.youtube.com/watch?v=KOvgfbBFZxk&t=6m

Sincerly yours,

[Jose Luis Ayerdis Espinoza]
Necronet.info |
LinkedIn<http://www.linkedin.com/pub/jose-luis-ayerdis-espinoza/28/7b4/704>|
Careers
StackOverflow <http://careers.stackoverflow.com/necronet>


2013/3/8 paalzza <paalzza@gmail.com>

> hi all
>
> why do we use stack (not just simple scalar) for request and application
> contexts?
> in what situation could there be more than one element in these stacks?
>

Re: [flask] question about flask internals

From:
paalzza
Date:
2013-03-09 @ 00:23
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    thanks for the link - it was very useful<br>
    <br>
    <div class="moz-cite-prefix">08.03.2013 21:05, Jose Ayerdis пишет:<br>
    </div>
    <blockquote
cite="mid:CAD5xQH_Cy6-UsMrzrEJE-SENNQXMhg3iUbZuxjRayF0+TY54SA@mail.gmail.com"
      type="cite">
      <div dir="ltr">Because Flask does not assume that is a single
        application that one that will be running therefore you need to
        stack them. This is more obvious whenever you are builting a
        plugin.
        <div><br>
        </div>
        <div><a moz-do-not-send="true"
            
href="http://www.youtube.com/watch?v=KOvgfbBFZxk&t=6m">http://www.youtube.com/watch?v=KOvgfbBFZxk&t=6m</a><br>
        </div>
      </div>
      <div class="gmail_extra"><br clear="all">
        <div>Sincerly yours,<br>
          <br>
          [Jose Luis Ayerdis Espinoza]
          <div><a moz-do-not-send="true" href="http://Necronet.info"
              target="_blank">Necronet.info</a> | <a
              moz-do-not-send="true"
              
href="http://www.linkedin.com/pub/jose-luis-ayerdis-espinoza/28/7b4/704"
              target="_blank">LinkedIn</a> | <a moz-do-not-send="true"
              href="http://careers.stackoverflow.com/necronet"
              target="_blank">Careers StackOverflow</a></div>
        </div>
        <br>
        <br>
        <div class="gmail_quote">2013/3/8 paalzza <span dir="ltr"><<a
              moz-do-not-send="true" href="mailto:paalzza@gmail.com"
              target="_blank">paalzza@gmail.com</a>></span><br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            hi all<br>
            <br>
            why do we use stack (not just simple scalar) for request and
            application<br>
            contexts?<br>
            in what situation could there be more than one element in
            these stacks?<br>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </body>
</html>

Re: [flask] question about flask internals

From:
Markus Unterwaditzer
Date:
2013-03-08 @ 18:03
paalzza <paalzza@gmail.com> wrote:

>hi all
>
>why do we use stack (not just simple scalar) for request and
>application 
>contexts?
>in what situation could there be more than one element in these stacks?

Quoting from http://flask.pocoo.org/docs/reqcontext/:

>Because the request context is internally maintained as a stack you can 
push and pop multiple times. This is very handy to implement things like 
internal redirects.

Of course there are only a few cases where this is helpful, but it still 
makes for nice design.

-- Markus (from phone)

Re: [flask] question about flask internals

From:
paalzza
Date:
2013-03-09 @ 00:26
"""This is very handy to implement things like internal redirects."""

can you point to some place to look for this use case, if you know? maybe 
in some examples, tests?



08.03.2013 22:03, Markus Unterwaditzer пишет:
> paalzza <paalzza@gmail.com> wrote:
>
>> hi all
>>
>> why do we use stack (not just simple scalar) for request and
>> application
>> contexts?
>> in what situation could there be more than one element in these stacks?
> Quoting from http://flask.pocoo.org/docs/reqcontext/:
>
>> Because the request context is internally maintained as a stack you can
push and pop multiple times. This is very handy to implement things like 
internal redirects.
> Of course there are only a few cases where this is helpful, but it still
makes for nice design.
>
> -- Markus (from phone)
>

Re: [flask] question about flask internals

From:
Markus Unterwaditzer
Date:
2013-03-09 @ 08:48
On 2013-03-09 01:26, paalzza wrote:
> """This is very handy to implement things like internal redirects."""
> 
> can you point to some place to look for this use case, if you know?
> maybe in some examples, tests?

This is going to be hardly useful in practice, but:

     import flask
     app = flask.Flask(__name__)

     @app.route('/sup')
     def sup():
         assert flask.request.path == '/sup'
         return 'Sup.'

     @app.route('/')
     def index():
         assert app.test_client().get('/sup').data == 'Sup.'
         return 'Woohoo!'

     app.run(debug=True)