Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out what port Django instance is running on?

Tags:

port

django

Is there any way to find out what port a Django instance is listening on from within the code?

like image 535
exupero Avatar asked Dec 13 '11 19:12

exupero


2 Answers

You can get the info through the HttpRequest. Checkout the Django Docs here.

This can be accessed through the META attribute which is a dictionary containing the HTTP header info.

Example:

def someView(request):
    #Try printing to screen
    print request.META['SERVER_PORT']
    ...
    return(response)
like image 121
mshell_lauren Avatar answered Nov 16 '22 02:11

mshell_lauren


maybe request.META['SERVER_PORT']

or are you not in a view?

like image 30
second Avatar answered Nov 16 '22 01:11

second