Python Django framework notes (1): installation and project creation

 #Recommend a book "Python Core Programming" (suitable for a certain foundation), written by American Wesley Chun, JD.com and Taobao should have it. I think it's well written, detailed, concise, and full of dry goods. Unlike some books, it's useless to read the whole book.

(1)      Web framework

    In addition to writing from the bottom, web development can also be developed on the basis of other people's existing, simplifying the development process. These web development environments are collectively referred to as web frameworks, and their goal is to help developers simplify their work, such as providing some functions to complete some common tasks, or providing some resources to reduce the workload of creating, updating, executing or extending applications.

A Python web framework can be either a single or multiple subcomponents, or a complete full-stack system. The term "full stack" refers to code that can develop all stages and layers of a web application. The framework can provide all related services such as web server, database ORM, templates and all required middleware hooks. Some also provide JavaScript libraries. Django is one of these well-known web frameworks.

(2)      Projects and applications

    What are projects and apps in Django? Simply put, a project can be thought of as a series of files that create and run a complete Web site. Under the project folder, there are one or more subfolders, each with a specific function, called an application. Apps don't have to be in the project folder. An application can focus on the functionality of one aspect of a project, or it can be used as a generic component for different projects. An application is a sub-module with a specific function, and these sub-modules can be combined to complete the function of the Web site. Such as managing user/reader feedback, updating real-time information, processing data, aggregating data from sites, etc.

(3)      Installation

    pip install django

(4)      Create a project

     Because the IDE I use is Pycharm, the following two methods are explained.

(1) Through the command line (mysite is the project name, custom)

django-admin.py startproject mysite

    After the command is executed, you can see a mysite folder in the directory

(2) Through IDE (Pycharm)

 

After creation, you should see the following files

 

Django project file

file name

illustrate

__init__.py

tell Python that this is a package

settings.py

Project related configuration

urls.py

global url configuration

wsgi.py

For WSGI compatible entry.

manage.py

Application command line interface

https://docs.djangoproject.com/en/dev/intro/tutorial01/

Details can be found at this address

(5)      Running the development server

Modify the following 2 lines of code in the settings.py file, and do not modify it, it will not affect the service startup

1  # LANGUAGE_CODE = 'en-us' 
2 LANGUAGE_CODE = ' zh_hans '  # Set to Simplified Chinese 
3  
4  # TIME_ZONE = 'UTC' 
5 TIME_ZONE = ' Asia/Shanghai '  # Set time zone

Execute the command python manage.py runserver to start the service, and then access

The server runs locally and is dedicated to the development phase.

1. Using the development server, you can run and test projects and applications directly without the need for a full production environment.

2. The development server automatically detects when changes are made to Python source files and modules are reloaded. This saves both

Time, but also easy to use the system, no need to manually restart every time after editing the code.

At this point, a django project has been created, and the next article explains how to create an application.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325013470&siteId=291194637