官术网_书友最值得收藏!

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.
主站蜘蛛池模板: 宜都市| 淳安县| 东宁县| 富平县| 灯塔市| 海伦市| 新乡市| 苍梧县| 克拉玛依市| 阳城县| 和平县| 子洲县| 洪泽县| 正蓝旗| 平罗县| 北川| 大埔区| 巴青县| 塔河县| 阳曲县| 元阳县| 诏安县| 东辽县| 习水县| 聂荣县| 麦盖提县| 福建省| 高雄市| 哈巴河县| 海晏县| 巴楚县| 凤山市| 聂荣县| 海兴县| 和林格尔县| 自治县| 隆回县| 礼泉县| 青田县| 新龙县| 宣化县|