3

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.

Run
  • 54,938
  • 169
  • 450
  • 748
  • `http://127.0.0.1` basically means "this machine", so it is running on `119.237.27.131` – Jonas Grumann May 18 '17 at 15:06
  • @JonasGiuro but I get this error on my browser when I check it at http://119.237.27.131:8000/ - `This site can’t be reached 119.237.27.131 refused to connect.`. Anything else I have missed? – Run May 18 '17 at 15:12
  • 4
    1) Django 1.5 has been unsupported for a long time, you should update to a supported version. 2) `manage.py runserver` is a development server, it should never be used in production. Use a proper WSGI server such as Apache/mod_wsgi, Gunicorn or uwsgi. See [How to deploy with WSGI](https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/). – knbk May 18 '17 at 15:13
  • @knbk I am taking over this django project. It wasn't me developed it. And I don't much about django. So I think it is better to keep it as it is. – Run May 18 '17 at 15:17

1 Answers1

7

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.

fixmycode
  • 8,220
  • 2
  • 28
  • 43
  • thanks for the answer. i hjave `Gunicorn` installed but how do I run the app with it? – Run May 18 '17 at 15:20
  • if Gunicorn is installed, you should point it to the `application` variable declared on your project's `wsgi.py` module. An example call would be: `gunicorn wsgi:application -b 127.0.0.1:8000`. it would accomplish the same as calling `gunicorn wsgi:application`. – fixmycode May 18 '17 at 15:26
  • where is `wsgi.py module`? do I need to configure anything in there? – Run May 18 '17 at 15:30
  • btw, how can check whether `Gunicorn` is installed correctly? why do i get this `$ gunicorn --version The program 'gunicorn' is currently not installed. You can install it by typing: sudo apt install gunicorn` – Run May 18 '17 at 15:37
  • 1
    `your_project_folder/your_project_name/wsgi.py`, it's the same folder where your `settings.py` module is. As far as I know, Django generates the file with everything you need to start the app, I've never had to modify it, but there are some development tools that modify that process. – fixmycode May 18 '17 at 15:38
  • 1
    you're getting that because you haven't installed Gunicorn. – fixmycode May 18 '17 at 15:39
  • thanks. this is how installed `pip install gunicorn` but why it asks me to install it again with `sudo apt install gunicorn`? it is so confusing! – Run May 18 '17 at 15:39
  • Also, i think it is a legacy of django - 1.5 that i am taking over. It has no `wsgi.py` – Run May 18 '17 at 15:51