Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Django creates the first project


May 14, 2021 Django


Table of contents


Django creates the first project

In this chapter we'll show you how to create a project using Django.

Use django-admin.py to create a project named :

  django-admin startproject xxx

Once created, we can look at the catalog structure of the next project:

[root@solar ~]# cd HelloWorld/
[root@solar HelloWorld]# tree
. manage.py 管理器
|--*** 
|   |-- __init__.py 包
|   |-- settings.py  设置文件
|   |-- urls.py   路由
|   `-- wsgi.py   部署

Catalog description:

  • HelloWorld: Container for the project.
  • manage.py: A useful command-line tool that lets you interact with the Django project in a variety of ways.
  • HelloWorld/__init__.py: An empty file that tells Python that the directory is a Python package.
  • HelloWorld/settings.py: Settings/configuration of the Django project.
  • HelloWorld/urls.py: URL statement for the Django project; A "directory" of Django-driven websites.
  • HelloWorld/wsgi .py: A entrance to a WSGI-compatible web server to run your project.

Creating an app module automatically generates an app folder that includes several files:

python manage.py startapp app

Description of each directory:

  • init.py package
  • admin.py manages the background
  • apps.py
  • migrations
  • init.py migration
  • model.py model
  • test.py test
  • view.py view

Find the contents of the package in the setting.py and register INSTALLED_APPS app module in the table:

INSTALLED_APPS = [

    'django.contrib.admin',

    'django.contrib.auth',

    'django.contrib.contenttypes',

    'django.contrib.sessions',

    'django.contrib.messages',

    'django.contrib.staticfiles',

    'app',

Enter the command under the package to start the project:

python manage.py runserver

Enter your server's ip and port number in the browser, and if you start normally, you'll get the following interface, which means that the project creation is complete:

Django creates the first project