Django (2)-Create a project and the introduction of the default project directory structure

1. Create a Django project

If you create a django project with a project name of mysite1, execute the following command

django-admin startproject mysite1

as follows:

Insert picture description here

2. Start the project

Enter the directory and execute (note that you need to confirm your python version number here. If the python command refers to python2, the python3 command is the version of python3.x. In the following commands, python is replaced with python3. This is because python in the environment The command entered is the python3.9 version, so you can use python directly):

python manage.py runserver

If the following error occurs, it means that port 8000 is occupied.

Insert picture description here


At this time, you can kill the process
currently occupying port 8000 as follows: 1) Open the cmd window and execute the following command to find the process number currently occupying port 8000

netstat  -ano|findstr 8000
Insert picture description here


2) Execute the following command again to see that the process number corresponds to the execution program

tasklist | findstr 12704
Insert picture description here


3) Determine whether the queried application is useful, if it is not useful, you can use the following command to kill it

taskkill /pid 12704 -F

Here to explain, the KGService.exe program is the process that Kugou Music uses to connect to the network. If this process is killed, Kugou Music cannot continue to listen to music online, etc., so if it’s your own computer, and you often like it If you listen to music, it is not recommended to kill this process here, so you can change the port number by not using django's default port 8000, such as 8080, then execute the following command:

python manage.py runserver 8080

The following indicates that the startup has been successful

Insert picture description here


. Open http://127.0.0.1:8080 in the browser to open the address of the project started by django. As shown below, you can see that the django project has been started successfully

Insert picture description here

3. Directory structure

The default directory after creation is as follows. Note that the db.sqlite3 file is not available after the project is created. When the project is started, such a database file will be created by default.

**Bold style**
  • manage.py: The various operation commands for project management created by django are triggered through the manage.py file, and all the commands provided by django project management can be listed through python manage.py
(django-5F60hEIM) (python39) G:\src\django\mysite1>python manage.py
Type 'manage.py help <subcommand>' for help on a specific subcommand.

Available subcommands:

[auth]
   changepassword
   createsuperuser

[contenttypes]
   remove_stale_contenttypes

[django]
   check
   compilemessages
   createcachetable
   dbshell
   diffsettings
   dumpdata
   flush
   inspectdb
   loaddata
   makemessages
   makemigrations
   migrate
   sendtestemail
   shell
   showmigrations
   sqlflush
   sqlmigrate
   sqlsequencereset
   squashmigrations
   startapp
   startproject
   test
   testserver

[sessions]
   clearsessions

[staticfiles]
   collectstatic
   findstatic
   runserver

(django-5F60hEIM) (python39) G:\src\django\mysite1>

  • The mysite1 folder, also known as the project folder with the same name, contains the following files:
  • init .py: the logo file of the Python package
  • wsgi.py: The configuration file of the WEB service gateway, which will be used when the Django project is officially launched
  • urls.py: The main route configuration of the project. If the HTTP request enters the Django project, it will first enter this file
  • settings.py: The configuration file of the project, which contains all the configuration required when the project is started
  • asgi.py: Asynchronous service gateway interface, which is an extension of wsgi.py and supports