Django - how to run it on a production server? - django

I am new to Django Project. I have my app moved to my production server and I have it run:
$ python manage.py runserver
>>> Starting gulp watch
>>> gulp watch gulp process on pid 30427
Validating models...
0 errors found
May 18, 2017 - 15:57:08
Django version 1.5.12, using settings 'website.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
But it is a production server with an IP, eg: 119.237.27.131
So it can't be running at http://127.0.0.1:8000/
Then what should I do so that the app is running on http://119.237.27.131:8000/ instead?
Any ideas?
Btw, where is 'website.settings'?
EDIT:
When I check the app at http://119.237.27.131:8000/
I get this error:
This site can’t be reached
119.237.27.131 refused to connect.

If you start the development server without any parameters, the server will start at localhost:8000, but it can't be accessed from outside the machine. To allow that, you should start the server like this:
python manage.py runserver 0.0.0.0:8000
That will allow you to connect from another machine, on the machine's IP address, like http://119.237.27.131:8000/
A word of warning: the development server is not a production-ready server. You should use a WSGI server like Gunicorn or another tool to serve your application. Do not use the development server in a production setting, it's not safe!! Read more about that here.

Related

django app not being served on digitalocean droplet

I'm following this tutorial online https://simpleisbetterthancomplex.com/tutorial/2016/10/14/how-to-deploy-to-digital-ocean.html
I get to an intermediary step where I want to check if I can access the app on the IP address. I run python manage.py runserver 0.0.0.0:8000 which returns the following:
System check identified no issues (0 silenced).
November 22, 2018 - 17:41:08
Django version 2.1.3, using settings 'mysite.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
So no errors. Then I navigate to my_droplet_ip:8000 and I get a timeout. "took to long to respond."
I am running the runserver command from a user rather than root. Don't know if that matters...
Any idea what's going on here?
I had to expose the port 8000 by running the command sudo ufw allow 8080. Wasn't mentioned anywhere in the tutorial...

Issues with accessing Django app on remote server; manually assigning IP address does not work [duplicate]

This is probably a very basic question. I SSH to my virtual Ubuntu server and start a django webserver running on localhost:
Downloading/unpacking django
Downloading Django-1.9.5-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded
Installing collected packages: django
Successfully installed django
Cleaning up...
Performing system checks...
System check identified no issues (0 silenced).
You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.
April 13, 2016 - 14:16:19
Django version 1.9.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
The Ubuntu server has a static IP [x.xxx.xxx.xxx] so from another machine on another network I try to access the above website in a browser using that static IP address:
x.xxx.xxx.xxx:8000
But I get:
This site can’t be reached
x.xxx.xxx.xxx refused to connect.
ERR_CONNECTION_REFUSED
So I assume that I cannot access the website like this and that is only available on the host it self even though the host has an external/static IP address?
Edit:
The answer is also in:
https://docs.djangoproject.com/en/1.9/intro/tutorial01/#the-development-server
python manage.py runserver 0.0.0.0:8000
You need to run your web server on 0.0.0.0:8000, then externally you would use either ip or host name to access. Using 0.0.0.0 means the django service would listen to all configured network interfaces.
Check wikipedia on details about 0.0.0.0.
Another answer on serverfault could be helpful.

django tutorial returns 'ERR_EMPTY_RESPONSE'

I'm following the django tutorial: version 1.8, Ubuntu 10.04, python 3.4 in a virtual environment. I seem to create a django project (yatest) on my Ubuntu server just fine and I start the development server:
(v1)cj#drop1:~/www/yatest$ python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
August 09, 2015 - 04:37:33
Django version 1.8.3, using settings 'yatest.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
but when I browse to http://myserver:8000 all I get in response is 'ERR_EMPTY_RESPONSE'.
This is the first part of the tutorial before an app is even created. At this early stage in the tutorial it doesn't mention any error log I can check. My telnet client doesn't say anything crashed, and 'ctl-c' will shutdown the server process with no complaints.
Using netstat -lntp I verified no other processes are using port 8000. I do not have Apache installed. I do have gunicorn and nginx installed but both are stopped and not in use yet in the tutorial.
I'm rather new to linux; I could use some help finding an error log or other debugging tools to solve this. I don't doubt I've missed some basic OS setting or something to enable TCP access, etc..
Thanks
Clark
Found my mistake. When starting a dev django server on dedicated server one MUST include the dedicated server's address in the command. This is not needed when launching a dev server on the same machine as your browser. So instead of
$python manage.py runserver
you have to run
$python manage.py runserver <server ip>:8000.
So this is my inglorious start on stack exchange. You saw nothing! :P
If you're running natively in an virtual envrionment, then you need to specify a port and address:
python manage.py runserver 127.0.0.1:8000
For containers, it's easiest to listen to all addresses:
python manage.py runserver 0.0.0.0:8000
For anybody using PyCharm in a docker environment, it's also worth knowing that PyCharm will override your docker-compose configuration to change the runserver command to bind to the port specified in the Host option in your Run/Debug Configurations window.
Make sure you set the Host to 0.0.0.0 and the port to 8000 if you want to use the debugger etc.
If you don't want the trouble to determine server ip (ie when you're using containers), you can listen to 0.0.0.0:8000
python manage.py runserver 0.0.0.0:8000

Changing localhost to public IP in a VM

I am testing RTD to build our API docs implementation, so running a local installation of RTD in a virtualenv within a debian VM. The ./manage.py runserver command runs the RTD server successfully.
Validating models...
0 errors found
March 25, 2015 - 03:11:57
Django version 1.6.10, using settings 'settings.sqlite'
Starting development server at http://127.0.0.1:8000/
To access the RTD admin console from my laptop browser (outside the VM) I would like to change the localhost to the public IP. For that, I changed the IP references in:
/etc/hosts
settings/sqlite.py (section
Internal_ips, and a few other occurrences)
But, it continues to build the server at http://127.0.0.1:8000/
Where should I be configuring this? What else should I be doing?
RESOLVED
Run the RTD server as:
./manage.py runserver 0.0.0.0:8000
OR
./manage.py runserver [VM IP ADDRESS]:8000

Django & Apache: How to debug on Testing server

I am trying to debug an issue that happens on our testing server. So how do I make it so that I can access our testing server when I start Django by typing:
python manage.py runserver
?
Does it have to pass through Apache? If so, I need to configure Apache somehow but I am not using mod_wsgi and so, don't know how to do this.
Thanks! :)
the test server runs its own web server. the defaul options starts a server on
http://127.0.0.1:8000/, which you can then open in your browser
you can specify an optional ip address/server using
manage.py runserver ip:port
using ip 0.0.0.0 for all network interfaces