Launching Django's development server

Now, we can launch Django's development server to compose and send HTTP requests to our unsecured web service. Remember that we will add security later.

Execute the following command in a Linux or macOS Terminal, or in the Windows Command Prompt or Powershell that has our previously created virtual environment activated. Make sure you are in the restful01 folder within the virtual environment's main folder:

    python manage.py runserver

The following lines show the output after we execute the previous command. The development server is listening at port 8000:

    Performing system checks...
    
    System check identified no issues (0 silenced).
    October 09, 2017 - 18:42:30
    Django version 1.11.5, using settings 'restful01.settings'
    Starting development server at http://127.0.0.1:8000/
    Quit the server with CTRL-BREAK.

With the previous command, we will start the Django development server and we will only be able to access it on our development computer. The previous command starts the development server at the default IP address, that is, 127.0.0.1 (localhost). It is not possible to access this IP address from other computers or devices connected to our LAN. Thus, if we want to make HTTP requests to our API from other computers or devices connected to our LAN, we should use the development computer IP address, 0.0.0.0 (for IPv4 configurations) or :: (for IPv6 configurations) as the desired IP address for our development server.

If we specify 0.0.0.0 as the desired IP address for IPv4 configurations, the development server will listen on every interface on port 8000. When we specify :: for IPv6 configurations, it will have the same effect. In addition, it is necessary to open the default port 8000 in our firewalls (software and/or hardware) and configure port-forwarding to the computer that is running the development server. The following command launches Django's development server in an IPv4 configuration and allows requests to be made from other computers and devices connected to our LAN:

    python manage.py runserver 0.0.0.0:8000 

If you decide to compose and send HTTP requests from other computers or devices connected to the LAN, remember that you have to use the development computer's assigned IP address instead of localhost. For example, if the computer's assigned IPv4 IP address is 192.168.2.103, instead of localhost:8000, you should use 192.168.2.103:8000. Of course, you can also use the hostname instead of the IP address.

The previously explained configurations are very important because mobile devices might be the consumers of our RESTful Web Services and we will always want to test the apps that make use of our web services and APIs in our development environments.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.80.101