程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Django chapter I project construction (illustrated and easy to start)

編輯:Python

The article contains columns
—Django from ( Easy tutorial with pictures and texts ) special column —!!

Content :
《Django Chapter II addition, deletion, modification and investigation 》

Django Project structures,

  • python Common framework
    • One 、 What is a framework ?
    • Two 、MVC and MVT Model
    • 3、 ... and 、django Installation
  • establish django project
    • One 、 Run the project
    • Two 、 design sketch !!
  • Overall process

python Common framework

1. Take care of everything django( Known as the integrity of the framework )
2. Strive to streamline web.py and Tornado
3. The Cenozoic era is the framework Flask and Bottle

One 、 What is a framework ?

In order to improve our efficiency in completing the project , We will use some of the lowest and most basic in the project
Foundation ( The main structure of the program , The skeleton of the program ) Pack your things into semi-finished products , And beat these
The half layer of the package is the frame .
Advantages and disadvantages of framework : Code can be reused 、 mature 、 steady 、 Easy to expand 、 Easy maintenance

Two 、MVC and MVT Model

django by MVT Model (templates - view - model)
M:Model, Responsible for interacting with the database , Build a model
V:View, View layer , Accept page requests , Respond
T:Template, Templates , It is writing html、css、js Templates , Generally speaking, it is what is displayed in the web page

3、 ... and 、django Installation

First you need to download python The latest version , You can download it directly on the official website , Using shortcut keys
windows+r Enter... In the run interface cmd, open Task manager

Type in

pip install django

You can download it. django The latest version among (pip yes python Management pack tools , You can
pip install , uninstall , to update . see django edition :
stay cmd In Task Manager Input :python Press enter to enter python Interactive systems , And enter the :

import django
django.get_version()
exit()

Pictured :

You can display its version , among get_version() Equivalent to a view version of the function
exit() sign out python shell

establish django project

Example : Let's go to the desktop in the task manager , And enter the ( The last one demo It's custom
The righteous , You can name anything )

django.admin startproject demo

You can see that the desktop generates a file , Double-click to open

There's a demo There's another one in the file manage.py( This is used to run )

Double click in demo The following documents are included after the document :

  • The meaning of each document here

__init.py__: Tell the system that this is a problem python package,django Configuration of miner
setting.py: Yes django Basic settings of the framework , You can pair... For functions django Set up the database , Language, etc.

__urls.py__:URL The configuration file , Quite a directory , Receive page requests , Jump to the target object , This object can be an application url.py, It may also be a view function

__asgi.py__ and __wsgi.py__: All are python Designed server gateway interface

One 、 Run the project

Now let's try to run the project : Enter... Under task manager

python manage.py runserver

After successful operation, as shown in the figure

Two 、 design sketch !!

Let's copy the above
http://127.0.0.1:8000 And open it in the web page, as shown in the figure :

🥳 The successful running ! Congratulations on your success in building your own project ( This page is not configured URL route
when ,django Display your own page )

Overall process

 install django
Use windows+R Input cmd Open Task Manager
Use cd(change dictionary) Enter the directory where the project is stored
stay cmd Input in :django-admin startproject web
cd Enter the project directory , And enter :python manage.py runserver
stay cmd Copy... In the pop-up prompt url Address to web page open , The project was built successfully !
This is the use of cmd How to quickly build a project , You can also do it in pycharm To establish django But the configuration is relatively complicated , Interested students search for relevant information to find out .
 Come here , If you have any questions about adding, deleting, modifying and checking
‍ Welcome private bloggers to ask questions , Bloggers will do their best to answer your doubts !‍
🥳 If it helps you , Your praise is the greatest support for bloggers !!🥳

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved