Jin Nii Sama
Jin Nii Sama

Reputation: 747

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

As what the title said, is it possible to run 2 django project at the same time ? Since by default, all django run by http://127.0.0.1:8000/. Is there anyway i can change the port number for both the django project ?

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. I also cant seems to find much information about this.

The only solution i found which is running this command:

manage.py runserver 8005

will allow the django project to run in 8005 port.

But is it possible to do it without writing the command and just do it in the settings.py or other file ? As i know this is just for development phrase. If its on production, it cannot use in this way.

Upvotes: 6

Views: 6550

Answers (2)

Jin Nii Sama
Jin Nii Sama

Reputation: 747

I found an answer from this post: django change default runserver port

This is achieve by modifying the manage.py file by adding this line

# Override default port for `runserver` command
from django.core.management.commands.runserver import Command as runserver
runserver.default_port = "Port Number"

Upvotes: 3

Fadil Olamyy Wahab
Fadil Olamyy Wahab

Reputation: 626

Yes you can.

What you have to do is set up a management command and edit the runserver.DEFAULT_PORT variable for each app.

Follow the steps below to achieve this:

  • Create a management folder
  • Under the management folder, create a commands folder.
  • Inside the commands folder, create a runserver.py file and put the code below in it
import django.core.management.commands.runserver as runserver
runserver.DEFAULT_PORT="Your preferred port"

Note: You have to do this for both apps.

Then just import its Command class.

from django.core.management.commands.runserver import Command

Upvotes: 2

Related Questions