Creating a new app with Django

Now, we will create a new app with Django. We will follow the same steps we learned in Chapter 1, Installing the Required Software and Tools, in the Creating an app with Django section. However, in order to avoid repeating many steps, we will use the same restful01 project we had created in that chapter. Hence, we will just add a new app to an existing project.

Make sure you quit Django's development server. Remember that you just need to press Ctrl + C in the terminal or command-prompt window in which it is running. In case you weren't running Django's development server, make sure the virtual environment in which we have been working in the previous chapter is activated. Then, go to the restful01 folder within the 01 folder (the root folder for our virtual environment). The following commands use the default paths to go to this folder. In case you have used a different path for your virtual environment, make sure you replace the base path with the appropriate one.

In Linux or macOS, enter the following command:

cd ~/HillarDjangoREST/01/restful01

If you prefer the Command Prompt, run the following command in the Windows command line:

cd /d %USERPROFILE%HillarDjangoREST1
estful01

If you prefer Windows PowerShell, run the following command in Windows PowerShell:

cd /d $env:USERPROFILEHillarDjangoREST1
estful01
  

Then, run the following command to create a new Django app named drones within the restful01 Django project. The command won't produce any output:

    python manage.py startapp drones

The previous command creates a new restful01/drones sub-folder, with the following files:

  • views.py
  • tests.py
  • models.py
  • apps.py
  • admin.py
  • __init__.py

In addition, the restful01/drones folder will have a migrations sub-folder with an __init__.py Python script. The structure is the same as the one we analyzed in Chapter 1, Installing the Required Software and Tools, in the Understanding Django folders, files and configurations section.

..................Content has been hidden....................

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