request.is_local is false?

78 views
Skip to first unread message

Cássio Botaro

unread,
Apr 29, 2014, 7:56:58 PM4/29/14
to
When i do request.is_local in shell, result is False but i'm at localhost. Whats's the explanation? The correct  should not  be True?

Anthony

unread,
Apr 29, 2014, 11:09:12 PM4/29/14
to web...@googlegroups.com
I suppose technically, .is_local isn't really meaningful in the shell, as there is no HTTP request involved (.is_local refers to the source of an HTTP request). When the request object is created, .is_local defaults to False, and it is only set to True if an HTTP request comes in from localhost. Perhaps instead it should default to None and then set to either True or False in the case of a request. On the other hand, I suppose an argument could be made for explicitly setting it to True in the shell -- request.env.remote_addr is set to 127.0.0.1 in the shell, so setting .is_local to True would be consistent with that setting.

Anthony


On Tuesday, April 29, 2014 6:36:51 PM UTC-4, Cássio Botaro wrote:

Cássio Botaro

unread,
Apr 30, 2014, 11:30:16 AM4/30/14
to web...@googlegroups.com
Nice explanation Anthony. Thank you.

Cássio Botaro

unread,
Apr 30, 2014, 5:22:16 PM4/30/14
to web...@googlegroups.com
I try to use request.is_local to divide production enviroment and development. But with this behaviour, it fail when i go to shell.

Is  ' request.env.remote_addr ' the solution?

Anthony

unread,
Apr 30, 2014, 7:03:00 PM4/30/14
to web...@googlegroups.com
Are you just trying to determine if you're in the shell or not? If so, you can do:

if request.env.cmd_options.shell:
   
print "You're in the shell"

Anthony


On Wednesday, April 30, 2014 5:22:16 PM UTC-4, Cássio Botaro wrote:

Cássio Botaro

unread,
May 2, 2014, 6:57:16 AM5/2/14
to web...@googlegroups.com
One alternative is :

if request.is_local or request.env.cmd_options.shell:
    # developer configuration    
else:
    # production configuration


Reply all
Reply to author
Forward
0 new messages