How to Change the Default Runserver Port in Django


Yesterday, I was wondering how to run multiple apps parallelly and did some research to learn how to do it in Django. Today, I woke up early, and I thought I would share what I’ve learned in a quick article.

Many of us know that normally when we run a Django project, the default host is localhost, and the port number is 8000. If you want to run multiple applications at the same time from the localhost, we can change the port number and run the application parallelly.

For example, if you want to run your Django app using port 7000, then use the following command:

python manage.py runserver 7000

If you want to create multiple web projects and want to run from a separate server, then you need to configure the server IP using  ALLOWED_HOST configuration in the settings.py file.

Now, when you launch the application, use this server.

For example, if your server IP address is 127.10.10.10 and the port number is 7000, then you can use the following command to run the application.

python manage.py runserver 127.10.10.10:7000

That is how we change the default port number and server address in Django.

How to Change the Default Runserver Port in Django: An Example

Now, let me create a new Django project on my computer and walk you through the process.

So, first of all, open your command prompt or command line and start a new project by typing in the following command:

 django-admin startproject demo 

I named the project “demo”. Now, a project folder and files will be created automatically. Let’s go inside the project folder by using the cd command.

cd demo

Now, let’s run the project using a different port, let’s say 7000, and see what happens.

python manage.py runserver 7000

You’ll get a URL of the development server, as you can see in the screenshot below.

Copy that URL and paste it in on your web browser. You’ll be able to see the Django project running on the new port that we’ve given, which is 7000.

That’s it. Now, we can run multiple projects parallelly by changing the port number using the localhost server itself.

I hope this short tutorial was helpful. If you have any doubts or queries, feel free to ask them in the comments down below. I’ll be happy to help you.

I would appreciate it if you would be willing to share this article. It will encourage me to create more useful tutorials like this.

Happy coding!

Ashwin Joy

I'm the face behind Pythonista Planet. I learned my first programming language back in 2015. Ever since then, I've been learning programming and immersing myself in technology. On this site, I share everything that I've learned about computer programming.

2 thoughts on “How to Change the Default Runserver Port in Django

  1. thx bud..it was helpfull…i had 4 projects running the default 8000/local port. i am not a CS/IT fella. just learning python and django.
    when tried running a dvdrental(project from udemy), django keeps looking for url patterns in proj1. i never know why. this helped thx a many

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts