13👍
✅
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)
- Update model instance with dynamic field names
- What is the value of self._db by default in Django?
- When I use HttpResponseRedirect I get TypeError: quote_from_bytes() expected bytes in Django
- Django error cannot import name 'RemovedInDjango30Warning'
- Satchmo clonesatchmo.py ImportError: cannot import name execute_manager
3👍
I found this might be helpful if you need to know the port number or IP address out of the view(in models.py for example.)
import sys
import socket
logger.error(socket.gethostbyname(socket.gethostname())+"----"+sys.argv[-1])
This will give you an output like below:
192.168.1.222----0.0.0.0:8000
- Determine if Django is running under the development server
- Heroku: No default language could be detected for this app for python even with runtime.txt
2👍
Request’s have a method build in specifically for this.
def someView(request):
print(request.get_port())
👤Cody
- Render current status only on template in StreamingHttpResponse in Django
- Difference between Django and Django rest framework
Source:stackexchange.com