librelist archives

« back to archive

current request customizing flask object

current request customizing flask object

From:
Jose Ayerdis
Date:
2013-01-10 @ 12:19
Hello I am currently customizing flask object scpecifically the
make_response,

But I encountered one problem how can I get the request method from there?
I know that application context and request context are independantly
should I grab it from the *_request_ctx_stack *or there is simpler way? I
need it to read the Accept and decide wether the response should be
rendered as json or html with templates.

tks


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>

Re: current request customizing flask object

From:
Jose Ayerdis
Date:
2013-01-10 @ 12:36
Sorry I rushed into my last mail I figure it out like this

*from flask import _app_ctx_stack, request*

class CustomFlask(Flask):
def make_response(self, rv):
 *print request.accept_mimetypes*
return Flask.make_response(self,rv)

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/1/10 Jose Ayerdis <joseayerdis@gmail.com>

> Hello I am currently customizing flask object scpecifically the
> make_response,
>
> But I encountered one problem how can I get the request method from there?
> I know that application context and request context are independantly
> should I grab it from the *_request_ctx_stack *or there is simpler way? I
> need it to read the Accept and decide wether the response should be
> rendered as json or html with templates.
>
> tks
>
>
> 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>
>

Re: [flask] Re: current request customizing flask object

From:
Mihail Klimin
Date:
2013-01-10 @ 13:10
Hi Jose

Use something like this:

from flask import jsonify
...
def index()
    if request.json:
        return jsonify(...)
    else:
        return render_template(...)

See example in

https://github.com/mattupstate/flask-security/blob/develop/flask_security/views.py#L81

/Mike


2013/1/10 Jose Ayerdis <joseayerdis@gmail.com>

> Sorry I rushed into my last mail I figure it out like this
>
> *from flask import _app_ctx_stack, request*
>
> class CustomFlask(Flask):
> def make_response(self, rv):
>  *print request.accept_mimetypes*
> return Flask.make_response(self,rv)
>
> 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/1/10 Jose Ayerdis <joseayerdis@gmail.com>
>
>> Hello I am currently customizing flask object scpecifically the
>> make_response,
>>
>> But I encountered one problem how can I get the request method from
>> there? I know that application context and request context are
>> independantly should I grab it from the *_request_ctx_stack *or there is
>> simpler way? I need it to read the Accept and decide wether the response
>> should be rendered as json or html with templates.
>>
>> tks
>>
>>
>> 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>
>>
>
>


-- 
*С уважением, Климин Михаил.*

Re: [flask] Re: current request customizing flask object

From:
Jose Ayerdis
Date:
2013-01-10 @ 13:23
interesting that it has that json attribute, although I was doing the
custom flask to avoid having to decide in the function wether I have to
return a json or render html template.

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/1/10 Mihail Klimin <klinkin@gmail.com>

> Hi Jose
>
> Use something like this:
>
> from flask import jsonify
> ...
> def index()
>     if request.json:
>         return jsonify(...)
>     else:
>         return render_template(...)
>
> See example in
> 
https://github.com/mattupstate/flask-security/blob/develop/flask_security/views.py#L81
>
> /Mike
>
>
> 2013/1/10 Jose Ayerdis <joseayerdis@gmail.com>
>
>> Sorry I rushed into my last mail I figure it out like this
>>
>> *from flask import _app_ctx_stack, request*
>>
>> class CustomFlask(Flask):
>> def make_response(self, rv):
>>  *print request.accept_mimetypes*
>> return Flask.make_response(self,rv)
>>
>> 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/1/10 Jose Ayerdis <joseayerdis@gmail.com>
>>
>>> Hello I am currently customizing flask object scpecifically the
>>> make_response,
>>>
>>> But I encountered one problem how can I get the request method from
>>> there? I know that application context and request context are
>>> independantly should I grab it from the *_request_ctx_stack *or there
>>> is simpler way? I need it to read the Accept and decide wether the response
>>> should be rendered as json or html with templates.
>>>
>>> tks
>>>
>>>
>>> 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>
>>>
>>
>>
>
>
> --
> *С уважением, Климин Михаил.*
>

Re: [flask] Re: current request customizing flask object

From:
klinkin
Date:
2013-01-10 @ 13:32
Jose,

see also flask source code: 
https://github.com/mitsuhiko/flask/blob/master/flask/wrappers.py#L92  


--  
C уважением,  
Климин Михаил.


четверг, 10 января 2013 г. в 17:23, Jose Ayerdis написал:

> interesting that it has that json attribute, although I was doing the 
custom flask to avoid having to decide in the function wether I have to 
return a json or render html template.
>  
> Sincerly yours,
>  
> [Jose Luis Ayerdis Espinoza]
> Necronet.info (http://Necronet.info) | LinkedIn 
(http://www.linkedin.com/pub/jose-luis-ayerdis-espinoza/28/7b4/704) | 
Careers StackOverflow (http://careers.stackoverflow.com/necronet)
>  
>  
>  
> 2013/1/10 Mihail Klimin <klinkin@gmail.com (mailto:klinkin@gmail.com)>
> > Hi Jose
> >  
> > Use something like this:
> >  
> > from flask import jsonify
> > ...
> > def index()  
> >     if request.json:
> >         return jsonify(...)
> >     else:
> >         return render_template(...)
> >  
> > See example in 
https://github.com/mattupstate/flask-security/blob/develop/flask_security/views.py#L81
> >  
> > /Mike
> >  
> >  
> > 2013/1/10 Jose Ayerdis <joseayerdis@gmail.com (mailto:joseayerdis@gmail.com)>
> > > Sorry I rushed into my last mail I figure it out like this  
> > >  
> > > from flask import _app_ctx_stack, request  
> > >  
> > > class CustomFlask(Flask):
> > > def make_response(self, rv):
> > > print request.accept_mimetypes
> > > return Flask.make_response(self,rv)
> > >  
> > >  
> > >  
> > > Sincerly yours,
> > >  
> > > [Jose Luis Ayerdis Espinoza]
> > > Necronet.info (http://Necronet.info) | LinkedIn 
(http://www.linkedin.com/pub/jose-luis-ayerdis-espinoza/28/7b4/704) | 
Careers StackOverflow (http://careers.stackoverflow.com/necronet)
> > >  
> > >  
> > >  
> > > 2013/1/10 Jose Ayerdis <joseayerdis@gmail.com 
(mailto:joseayerdis@gmail.com)>
> > > > Hello I am currently customizing flask object scpecifically the 
make_response,
> > > >  
> > > > But I encountered one problem how can I get the request method 
from there? I know that application context and request context are 
independantly should I grab it from the _request_ctx_stack or there is 
simpler way? I need it to read the Accept and decide wether the response 
should be rendered as json or html with templates.   
> > > >  
> > > > tks
> > > >  
> > > >  
> > > > Sincerly yours,
> > > >  
> > > > [Jose Luis Ayerdis Espinoza]
> > > > Necronet.info (http://Necronet.info) | LinkedIn 
(http://www.linkedin.com/pub/jose-luis-ayerdis-espinoza/28/7b4/704) | 
Careers StackOverflow (http://careers.stackoverflow.com/necronet)
> > > >  
> > > >  
> > > >  
> > >  
> > >  
> > >  
> >  
> >  
> >  
> > --  
> > С уважением, Климин Михаил.
>  

Re: [flask] Re: current request customizing flask object

From:
Jose Ayerdis
Date:
2013-01-11 @ 02:43
But json checks for request.mimetype, but that is a attribute of the body,
I actually need to check for accept_mimetype.



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/1/10 klinkin <klinkin@gmail.com>

> Jose,
>
> see also flask source code:
> https://github.com/mitsuhiko/flask/blob/master/flask/wrappers.py#L92
>
>
> --
> C уважением,
> Климин Михаил.
>
> четверг, 10 января 2013 г. в 17:23, Jose Ayerdis написал:
>
> interesting that it has that json attribute, although I was doing the
> custom flask to avoid having to decide in the function wether I have to
> return a json or render html template.
>
> 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/1/10 Mihail Klimin <klinkin@gmail.com>
>
> Hi Jose
>
> Use something like this:
>
> from flask import jsonify
> ...
> def index()
>     if request.json:
>         return jsonify(...)
>     else:
>         return render_template(...)
>
> See example in
> 
https://github.com/mattupstate/flask-security/blob/develop/flask_security/views.py#L81
>
> /Mike
>
>
> 2013/1/10 Jose Ayerdis <joseayerdis@gmail.com>
>
> Sorry I rushed into my last mail I figure it out like this
>
> *from flask import _app_ctx_stack, request*
>
> class CustomFlask(Flask):
> def make_response(self, rv):
>  *print request.accept_mimetypes*
> return Flask.make_response(self,rv)
>
> 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/1/10 Jose Ayerdis <joseayerdis@gmail.com>
>
> Hello I am currently customizing flask object scpecifically the
> make_response,
>
> But I encountered one problem how can I get the request method from there?
> I know that application context and request context are independantly
> should I grab it from the *_request_ctx_stack *or there is simpler way? I
> need it to read the Accept and decide wether the response should be
> rendered as json or html with templates.
>
> tks
>
>
> 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>
>
>
>
>
>
> --
> *С уважением, Климин Михаил.*
>
>
>
>

Re: [flask] Re: current request customizing flask object

From:
Jose Ayerdis
Date:
2013-01-11 @ 05:10
I am wonder why request.mimetype is not set with the Accept headers in the
request instead that with the content-type. Since my assumption was

GET -> Accept
POST -> Content-type

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/1/11 Jose Ayerdis <joseayerdis@gmail.com>

> But json checks for request.mimetype, but that is a attribute of the body,
> I actually need to check for accept_mimetype.
>
>
>
> 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/1/10 klinkin <klinkin@gmail.com>
>
>> Jose,
>>
>> see also flask source code:
>> https://github.com/mitsuhiko/flask/blob/master/flask/wrappers.py#L92
>>
>>
>> --
>> C уважением,
>> Климин Михаил.
>>
>> четверг, 10 января 2013 г. в 17:23, Jose Ayerdis написал:
>>
>> interesting that it has that json attribute, although I was doing the
>> custom flask to avoid having to decide in the function wether I have to
>> return a json or render html template.
>>
>> 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/1/10 Mihail Klimin <klinkin@gmail.com>
>>
>> Hi Jose
>>
>> Use something like this:
>>
>> from flask import jsonify
>> ...
>> def index()
>>     if request.json:
>>         return jsonify(...)
>>     else:
>>         return render_template(...)
>>
>> See example in
>> 
https://github.com/mattupstate/flask-security/blob/develop/flask_security/views.py#L81
>>
>> /Mike
>>
>>
>> 2013/1/10 Jose Ayerdis <joseayerdis@gmail.com>
>>
>> Sorry I rushed into my last mail I figure it out like this
>>
>> *from flask import _app_ctx_stack, request*
>>
>> class CustomFlask(Flask):
>> def make_response(self, rv):
>>  *print request.accept_mimetypes*
>> return Flask.make_response(self,rv)
>>
>> 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/1/10 Jose Ayerdis <joseayerdis@gmail.com>
>>
>> Hello I am currently customizing flask object scpecifically the
>> make_response,
>>
>> But I encountered one problem how can I get the request method from
>> there? I know that application context and request context are
>> independantly should I grab it from the *_request_ctx_stack *or there is
>> simpler way? I need it to read the Accept and decide wether the response
>> should be rendered as json or html with templates.
>>
>> tks
>>
>>
>> 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>
>>
>>
>>
>>
>>
>> --
>> *С уважением, Климин Михаил.*
>>
>>
>>
>>
>