Running 2 django project in different port number at the same time.

3,702 views
Skip to first unread message

chern...@gmail.com

unread,
Jan 15, 2018, 11:31:20 PM1/15/18
to Django users
As what the title said, is it possible to run 2 django project at the same time ?

My task is this:
 Integration of django 1 api and django 2 api, to setup two django app, on same server / PC, with different port


As far from what i know, i can change the port number in the settings.py database section.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'Project',
        'USER': 'admin',
        'PASSWORD': 'pass1234',
        'HOST': 'localhost',
        'PORT': '',
    }
}

Do i change the port number here ? As default is http://127.0.0.1:8000/

So i change the 'PORT': '8001', but got this error instead:
could not connect to server: Connection refused (0x0000274D/10061)
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 8001?

Is there a way to set it up so i can run 2 different django project with different port number ?

chern...@gmail.com

unread,
Jan 15, 2018, 11:36:17 PM1/15/18
to Django users
I found another solution which is running this command

manage.py runserver 8005

But is it possible to do it without writing the command and just do it in the settings.py or other file ?

Jani Tiainen

unread,
Jan 15, 2018, 11:38:57 PM1/15/18
to django...@googlegroups.com
Hi.

If you want to run two devservers just define ip and port number when launching devserver.


16.1.2018 6.32 <chern...@gmail.com> kirjoitti:
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ae611f43-645f-42a9-a78b-a9ef6fd22eb7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jani Tiainen

unread,
Jan 15, 2018, 11:44:54 PM1/15/18
to django...@googlegroups.com
No. Development server is not meant to be final serving solution and it doesn't have any configuration besides the command line.

16.1.2018 6.37 <chern...@gmail.com> kirjoitti:
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Antonis Christofides

unread,
Jan 16, 2018, 2:00:37 AM1/16/18
to django...@googlegroups.com

Hello,

DATABASES['...']['PORT'] is the port to which the database server is listening (your django app is a client of the database, and it connects to that port in order to access the database); it has nothing to do with what you want.

AFAIK specifying the port number in "runserver" is the only way to do what you want in development.

Production is a whole another story.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

chern...@gmail.com

unread,
Jan 16, 2018, 2:12:50 AM1/16/18
to Django users
Then what must i do if i wanted to do it for production side? Is there any link/guide about how to change it ?

chern...@gmail.com

unread,
Jan 16, 2018, 2:47:21 AM1/16/18
to Django users
Define ip and port number is this link right : 
to change its port number and ip ?

Jani Tiainen

unread,
Jan 16, 2018, 5:06:22 AM1/16/18
to django...@googlegroups.com
Hi.

Please note that runserver command is only meant to ease developing your site with Django. In development you can run development server like:

./manage.py runserver 127.0.0.1:8000
./manage.py runserver 127.0.0.2:8001

But when deploying your site(s) to production procedure is different and depends which deployment model you do choose.

More information about production deployment: https://docs.djangoproject.com/en/2.0/howto/deployment/



16.1.2018 9.48 <chern...@gmail.com> kirjoitti:
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Jason

unread,
Jan 16, 2018, 6:29:44 AM1/16/18
to Django users
you need to configure your server to handle that pass through from web request to django.  With apache + mod_wsgi, it would be defined as a virtualhost in the conf files.  Nginx and gunicorn would be done in nginx configuration.

You could set it up such that


where /path/to/resource could be identical but would actually hit different projects deployed based in the django-app-[1,2] bit in the URL.

AVOID USING DEVSERVER FOR ANYTHING IN PRODUCTION

chern...@gmail.com

unread,
Jan 17, 2018, 2:43:21 AM1/17/18
to Django users
wait, i configure the manage.py by inserting this
# Override default port for `runserver` command
from django.core.management.commands.runserver import Command as runserver

runserver.default_port = "8001"

Is this bad ?

Andréas Kühne

unread,
Jan 17, 2018, 3:52:54 AM1/17/18
to django...@googlegroups.com
Hi,

You shouldn't use the runserver command in production  - THAT is bad. There are several reasons for this, see here: https://docs.djangoproject.com/en/2.0/ref/django-admin/#runserver.

The main reasons are that there are no security checks, it reloads if changes are made in the code and it is not as fast as a production server. 

You should use some other type of uwsgi server to serve your code in production (mod_wsgi, gunicorn or uwsgi for example) and connect them to a webserver - see here for a setup example: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Deployment.

You can then run several uwsgi servers on one server of course.

Regards,

Andréas

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

chern...@gmail.com

unread,
Jan 17, 2018, 9:10:02 PM1/17/18
to Django users
Noted, thanks


On Tuesday, January 16, 2018 at 1:31:20 PM UTC+9, chern...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages