Re: Discovering the ip/port in use by runserver

2009-10-27 Thread tow

On Oct 27, 1:53 pm, Christian Joergensen  wrote:
>
> You could probably just read it from sys.argv ;)

;-) That had crossed my mind. I think it might actually be the most
robust way!

You have to do a bit of fiddling to make sure you don't grab an
option, and that you don't do this if you're not under runserver - but
this below is what I'm doing for now. It seems to Work For Me. This is
now in settings.py, with a bit of boilerplate to set some appropriate
variables.


def check_runserver_addrport():
import sys
if len(sys.argv) > 1 and sys.argv[1] == "runserver":
addrport = sys.argv[-1] if len(sys.argv) > 2 else
"127.0.0.1:8000"
if addrport.startswith("-"):
return
else:
   try:
addr, port = addrport.split(':')
   except ValueError:
addr, port = '', addrport
if not addr:
addr = '127.0.0.1'
return addr, port
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Discovering the ip/port in use by runserver

2009-10-27 Thread tow

Thanks. I'd seen that, and that does indeed work if you're in a view &
you've got access to a request object.

I was hoping that there was another way, useful when you didn't have a
request object to hand. I'm beginning to think the answer is "no"
though.

Toby

On Oct 27, 1:14 pm, Karen Tracey  wrote:
> On Tue, Oct 27, 2009 at 8:13 AM, tow  wrote:
>
> > Clearly I know what I did, I'm wondering if I can get a view inside
> > the django process to know what I did.
>
> http://docs.djangoproject.com/en/dev/ref/request-response/#django.htt...
>
> lists SERVER_PORT among the typical headers.
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Discovering the ip/port in use by runserver

2009-10-27 Thread Christian Joergensen

tow wrote:
> I know it uses whatever I specified. What I'm asking is, inside the
> django process, is it possible to find out what I specified?
> 
> ie, if I did "./manage.py runserver" - how do I find out, from a view
> inside the django process, that I'm running on localhost:8000?
> 
> if I did './manage.py runserver other.ip.address:", how do I find
> out, from a view inside the django process, that I'm running on
> some.other.ip.address:?
> 
> Clearly I know what I did, I'm wondering if I can get a view inside
> the django process to know what I did.

You could probably just read it from sys.argv ;)

/Christian

-- 
Christian Joergensen
http://www.technobabble.dk

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Discovering the ip/port in use by runserver

2009-10-27 Thread Karen Tracey
On Tue, Oct 27, 2009 at 8:13 AM, tow  wrote:

>
> Clearly I know what I did, I'm wondering if I can get a view inside
> the django process to know what I did.
>
>
>
http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.META

lists SERVER_PORT among the typical headers.

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Discovering the ip/port in use by runserver

2009-10-27 Thread tow

I know it uses whatever I specified. What I'm asking is, inside the
django process, is it possible to find out what I specified?

ie, if I did "./manage.py runserver" - how do I find out, from a view
inside the django process, that I'm running on localhost:8000?

if I did './manage.py runserver other.ip.address:", how do I find
out, from a view inside the django process, that I'm running on
some.other.ip.address:?

Clearly I know what I did, I'm wondering if I can get a view inside
the django process to know what I did.


On Oct 27, 7:17 am, Jani Tiainen  wrote:
> tow kirjoitti:
>
> > If you're running your django server through ./manage.py runserver, is
> > there a way, from within the django process, to discover which  IP
> > address and port are in use?
>
> It doesn't use anything it just listens whatever you specified at
> startup. Default is any local address (localhost), port 8000. Anything
> beyond that you know since you have to specify it explicitly.
>
> --
> Jani Tiainen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Discovering the ip/port in use by runserver

2009-10-27 Thread Larrik Jaerico

Perhaps he is looking for a way to get the values passed to runserver,
then?

On Oct 27, 3:17 am, Jani Tiainen  wrote:
> tow kirjoitti:
>
> > If you're running your django server through ./manage.py runserver, is
> > there a way, from within the django process, to discover which  IP
> > address and port are in use?
>
> It doesn't use anything it just listens whatever you specified at
> startup. Default is any local address (localhost), port 8000. Anything
> beyond that you know since you have to specify it explicitly.
>
> --
> Jani Tiainen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Discovering the ip/port in use by runserver

2009-10-27 Thread Jani Tiainen

tow kirjoitti:
> If you're running your django server through ./manage.py runserver, is
> there a way, from within the django process, to discover which  IP
> address and port are in use?

It doesn't use anything it just listens whatever you specified at 
startup. Default is any local address (localhost), port 8000. Anything 
beyond that you know since you have to specify it explicitly.

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Discovering the ip/port in use by runserver

2009-10-26 Thread tow

Other than something like this, obviously, which works, but is a bit
fragile & certainly not very nice:

def get_server_address_by_stack_inspection():
import inspect
for s in inspect.stack():
if (s[0].f_code.co_filename.endswith("django/core/
servers/basehttp.py")
and s[0].f_code.co_name == "run" and s
[0].f_code.co_argcount == 3):
return s[0].f_locals['server_address']


On Oct 26, 11:34 pm, tow  wrote:
> If you're running your django server through ./manage.py runserver, is
> there a way, from within the django process, to discover which  IP
> address and port are in use?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Discovering the ip/port in use by runserver

2009-10-26 Thread tow

If you're running your django server through ./manage.py runserver, is
there a way, from within the django process, to discover which  IP
address and port are in use?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---