Debugging remote dev server
Posted on Thu 06 March 2014 in posts
Allow runserver to accept requests from any address
By default, the runserver command will not accept outside connections.
python manage.py runserver 127.0.0.0:8000
This will only accept connections from 127.0.0.0, if you are connected to a remote server and not using port forwarding, then your address will not be recognized. To fix the issue, use:
python manage.py runserver 0.0.0.0:8000
Extend the INTERNAL_IPS Setting
When DEBUG = True, if your ip address is something other than 127.0.0.1 then you still will not be able to view the site in debug mode. To fix this, you must add your ip address that you are accessing the server from to the list of internal ips. Since your local ip address will change constantly, it is easier to wildcard it with your local network addresses. Wildcarding is not supported by the INTERNAL_IPS setting so it must be extended in your settings.py file.
if DEBUG: from fnmatch import fnmatch class glob_list(list): def __contains__(self, key): for elt in self: if fnmatch(key, elt): return True return False INTERNAL_IPS = glob_list(['127.0.0.1', '192.168.*.*'])
This will give you the ability to debug a remote dev server. However, you probably don't want to have that mess in your settings.py file. A better solution is to make a local_settings.py file that will be ignored by source control.
Extend the settings file to import a local_settings.py
try: from local_settings import * except ImportError: pass
Create a local_settings.py and move the code from above to extend internal ips into it, this time, you can remove the if DEBUG: statement if you will never have DEBUG = False on your dev server
from fnmatch import fnmatch class glob_list(list): def __contains__(self, key): for elt in self: if fnmatch(key, elt): return True return False INTERNAL_IPS = glob_list(['127.0.0.1', '192.168.*.*'])