21👍
request.build_absolute_uri('/')
or you could try
import socket
socket.gethostbyname(socket.gethostname())
20👍
With Django docs here, You can use:
domain = request.get_host()
# domain = 'localhost:8000'
- [Django]-How to get GET request values in Django?
- [Django]-Django.core.exceptions.ImproperlyConfigured: Error loading psycopg module: No module named psycopg
- [Django]-Django admin – make all fields readonly
6👍
If you want to know exactly the IP address that the development server is started with, you can use sys.argv
for this. The Django development server uses the same trick internally to restart the development server with the same arguments
Start development server:
manage.py runserver 127.0.0.1:8000
Get address in code:
if settings.DEBUG:
import sys
print sys.argv[-1]
This prints 127.0.0.1:8000
- [Django]-Generate a Unique String in Python/Django
- [Django]-How to create Password Field in Model Django
- [Django]-Could not parse the remainder
- [Django]-How do I use Django's logger to log a traceback when I tell it to?
- [Django]-Django : Filter query based on custom function
- [Django]-No URL to redirect to. Either provide a url or define a get_absolute_url method on the Model
0👍
import re
import subprocess
def get_ip_machine():
process = subprocess.Popen(['ifconfig'], stdout=subprocess.PIPE)
ip_regex = re.compile('(((1?[0-9]{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((1?[0-9]{1,2})|(2[0-4]\d)|(25[0-5]))')
return ip_regex.search(process.stdout.read(), re.MULTILINE).group()
- [Django]-Does get_or_create() have to save right away? (Django)
- [Django]-Django BooleanField as radio buttons?
- [Django]-Django – how to unit test a post request using request.FILES
Source:stackexchange.com