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

Creating an app with Django

Now, we will create our first app with Django and we will analyze the directory structure that Django creates. First, go to the root folder for the virtual environment: 01.

In Linux or macOS, enter the following command:

cd ~/HillarDjangoREST/01

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

cd /d %USERPROFILE%\HillarDjangoREST\01

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

cd /d $env:USERPROFILE\HillarDjangoREST\01  

In Linux or macOS, run the following command to create a new Django project named restful01. The command won't produce any output:

python bin/django-admin.py startproject restful01  

In Windows, in either Command Prompt or PowerShell, run the following command to create a new Django project named restful01. The command won't produce any output:

python Scripts\django-admin.py startproject restful01  

The previous command creates a restful01 folder with other subfolders and Python files. Now, go to the recently created restful01 folder. Just execute the following command on any platform:

cd restful01

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

python manage.py startapp toys

The previous command creates a new restful01/toys subfolder, with the following files:

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

In addition, the restful01/toys folder will have a migrations subfolder with an __init__.py Python script. The following diagram shows the folders and files in the directory tree, starting at the restful01 folder with two subfolders - toys and restful01:

主站蜘蛛池模板: 大石桥市| 合肥市| 新建县| 榆林市| 昭平县| 吕梁市| 安多县| 吕梁市| 新密市| 西昌市| 临西县| 宁化县| 钟山县| 江油市| 罗山县| 黄冈市| 孟津县| 永丰县| 安仁县| 临夏县| 稷山县| 苏州市| 庐江县| 隆安县| 凯里市| 沙坪坝区| 澄江县| 陕西省| 白城市| 鸡东县| 盘锦市| 广水市| 呼玛县| 抚宁县| 中山市| 闸北区| 疏勒县| 大埔县| 平原县| 清徐县| 合阳县|