How to Run Django-based Internal Service in the command line using non-default port

Posted on

Introduction

In this article, in the content, it will show about how to run a Django-based internal service. The process will be available by typing a certain command in the command line interface. Moreover, instead of using a default port, it will try to use another different port. So, the command will not run in its default or associated port but in another different port. The following are the steps for doing it :

  1. First of all, the most important step above all. Just execute the command line interface. The following one is the example of the command line interface execution :

    Microsoft Windows [Version 10.0.19042.1288]
    (c) Microsoft Corporation. All rights reserved.
    
    C:\Users\Personal>
    
  2. After successfully running or execute the command line interface,  go in to the root folder of the Django-based project. For an example as follows :

    C:\Users\Personal> cd C:\programming\python\project
    C:\programming\python\project>
    
  3. Before going futher, do not forget to activate any python virtual environment available. The following are the above to do it :

    C:\programming\python\project>env\Scripts\activate
     
    (env) C:\programming\python\project>
    
  4. After successfully activating the python virtual environment, just type the following command to run the Django-based internal service. Before doing that, take a look at the command patern as follows :

    python manage.py runserver port_number

    By default, if it is using the normal port, it will run the Django-based internal service. The Django-based internal service by default actually is using port 8000.  Using the following pattern above, the following is the actual execution of it using a non-default port which is port ‘8001’ :

    (env) C:\programming\python\project> python manage.py runserver 8001
    Type 'manage.py help' for usage.
    Watching for file changes with StatReloader
    Performing system checks...
    
    System check identified no issues (0 silenced).
    October 20, 2021 - 22:57:58
    Django version 3.2.6, using settings 'core.settings'
    Starting development server at http://127.0.0.1:8001/
    Quit the server with CTRL-BREAK.
    
    
  5. Last but least, just access the URL address of the Django-based internal service. The URL address is ‘http://127.0.0.1:8001/’ or ‘localhost:8001’. If there are no further error, the access to the URL address will displaying a normal output.

Leave a Reply