I & tall and configure a django

I & tall the Django package using the pip package manager:

# pip install Django

After the Django package is installed, the django-admin tool is used to manage the django project.

Create a project

Create a new django project using the django-admin tool:

$ django-admin startproject [项目名称]

An empty django project basic file structure is as follows:


├── 项目名称

│ ├──

│ ├── # 项目设置

│ ├── # 路由设置

│ └──

└── # 项目的管理脚本

A project 's root directory is a project management script that can be used to complete the creation of applications, running projects, and so on.

A subdirectory of the project under the root directory of the project will also have a subdirectory with the same as the project name, which saves some configuration of the project.

Create application

Unlike traditional web development frameworks, Django uses App to divide the web site into multiple functional modules, and a project is composed of multiple App, and a App can be reused by multiple projects.

Also use the django-admin tool to create a App in the project directory:

$ django-admin startapp [应用名称]

You can also perform project management script to create a new App:

$./ startapp [应用名称]

A newly created django application base file structure looks like this:





├── migrations

│ └──




An application needs to add a reference name to the INSTALLED_APPS list in the project profile, as follows:

# file: [项目名称]/










Run project

Execute the project management script, and use the runserver parameter to run the project:

$. /manager. Py runserver.

By default, the project ru & on the 8000 port, using to access the running project, and then the runserver parameter can add port numbe & to specify the project run port:

$./ runserver [端口号]

By default, projects launched with the application server that come with django can only be accessed by native computers ( unlike Tomcat, Jetty ).
If you need to make the project accessible to other machines in the intranet, use as an ip when it's started:

$./ runserver[端口号]

At the same time, add the allowed host ip in the ALLOWED_HOSTS column table in the project profile, allowing all host access to be configured as follows:

# file: [项目名称]/




About Couldn't import Django... erro &

An Couldn't import Django... error is output when the ./ runserver directive is executed, if the Django module is already installed correctly, you need to check the system default Python ve & ion.
If the system default uses Python with the Python version of Django, you should explicitly use the specified version of the Python interpreter to execute the script.

As an example of Python 3.6, the command is as follows:

python3.6 runserver

Developing a intellij project in a idea

A Python is installed in IntelliJ IDEA for Django project development.

Create a project

Support for creating Django projects directly in IntelliJ IDEA, check Django support when creating Python projects.

Import project

Choose Project from Existing Sources... Option, select the root directory of the Djangp project that you created.

After performing the project import step, convert the Django project to a standard IDEA project.
Completing the imported Django project doesn't execute immediately, and you need to configure the Django project information in the following path:

File => Project Structure => Project Settings => Facets => Django

  • Django project root project root path
  • Configuration files for Settings projects ( 项目名称 )
  • Manage script management script ( )

After you create the project 's run configuration ( Django server ), you can execute the project.

Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs