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

Learn python with a small hand # the world of Django in Python Web

編輯:Python

One 、Python Web And Django The world of

=========================

1. Django What is it?


Django It's a framework , For developing websites , The programming language used is Python, stay Django Common development templates are provided in , Let the programmer focus on the business part .

Djano advantage :

  1. Management backstage , It can be configured simply , A content management platform can be realized ;
  2. ORM, Object relation mapping , Convenient database operation ;
  3. Template system with front and rear ends separated ;

More , You have to learn before you can have a deep understanding of .

Django Because it's mainstream Python Web frame , So support MVC Pattern , about MVC It's easy to fall into concepts at the beginning of learning , Here's a simple explanation of the eraser .

MVC It's an abbreviation of three words , Namely (Model -View - Controller), The model is very mature Web Application design patterns .

  • M: Responsible for getting data from the database ;
  • V: Responsible for pushing data to users ;
  • C: stay M And V A controller that transfers data between two computers .

1.1 Django MVT Pattern

MVT yes Djongo The design pattern that comes with in , It is associated with MVC There are some differences , You can simply understand it as Django Bring it with you HTML Template file , And support template language ( The blog behind the template language will cover , Include placeholders , Branch , Circulation and other common operations ),Django Nothing is lost Controller, It's just that it does it on its own , It doesn't require too much developer involvement .

1.2 Other Python Web frame

be based on Python Linguistic Web There are a lot of frames , Common are Webpy、Flask、Bottle、Pyramid、Tornado. The third round of snowballing is mainly about Djando, Framework is a powerful tool to improve the efficiency of code writing , You can start with any learning , choice Django It's just that the frame reform is more popular in China , Pay attention to , There is no distinction between good and bad in terms of framework .

2. Web Develop the front knowledge


Front end knowledge

Front end knowledge includes HTML,CSS,Javascript , Hope to learn complete Web Development of students , This part of knowledge must be supplemented completely , It's very good for you , If there's a chance later , The eraser will do a separate set Web Front end column series .

HTTP Deal with the TCP/IP agreement

Web Development follows HTTP Protocol implemented , Therefore, this part also belongs to the necessary knowledge , Network protocol TCP/IP In the early stage of learning, we can post .

Linux Server knowledge

At present, the mainstream servers in China are Linux System , Although in Windows Up operation Python No problem at all , But take a long look , It is recommended to master Linux Server related knowledge .

Database system

As a Python R & D personnel , This part of knowledge cannot be omitted , In especial MySQL database , besides , To master skillfully SQL Language , It's also the top priority .

Cache system

Give priority to Redis

Data structures and design patterns

The core competitiveness of programmers , At the beginning of learning, it can be put behind , Including algorithms .

Operating system principle

A course in College , I believe many students have forgotten , Here's just a reminder , If you want your own way of programming , Farther away , It is suggested to supplement the knowledge of operating system principles .

3. Web Development of Python part


This column belongs to snowballing Python Extension of , therefore Python Relevant pre knowledge has been learned in the snowball .

  1. Operator ;
  2. data type , Integers , character string , list , Tuples , Dictionaries , aggregate ;
  3. Key types , character string , List and its object methods ;
  4. Tuple and dictionary related methods ;
  5. Branch and loop statements ;
  6. Modules and functions ;
  7. class , attribute , Method ;
  8. Regular expressions ;

4. These foundations , Do you have any impression ?


  1. There is a function in the mathematical operator divmod, Do you know how to use it ?
  2. Do dictionaries have order ,collections.OrderedDict What does it do ?
  3. How to set the default value of the dictionary ?
  4. deque collections.deque Have you ever studied ?
  5. Use os Can a module be imported into a module ?
  6. Python The order of finding variables is LEGB Do you ?
  7. Class __ What does the underline mean ?_ What does the underline mean ?
  8. Deep copy and shallow copy ;
  9. exec,eval,repr What do the three built-in functions do ?
  10. picklejsonshutil How to use the module ?

5. Django Installation and operation


install Djando It's very simple , Use the command line to install .

pip install django

The installation is successful. The contents that appear are :

Successfully installed asgiref-3.3.1 django-3.1.7 sqlparse-0.4.1

After installation, use the following code to test :

import django
print(django.get_version())

In the test environment variables are completely correct , Run the following command in the command window :

django-admin help

If everything is consistent with the picture above , You can continue to use the following command , Create a Django project .

django-admin startproject my_website

After running , Generate the following file structure in the corresponding folder .

stay my_website Another directory contains my_website Catalog , The directory is the entire project's configuration file directory , also manage.py file , Project management script .

  • my_website
    • my_website
    • __init__.py
    • asgi.py: ASGI Server deployment information
    • setting.py: Project configuration information
    • urls.py: Website routing information
    • wagi.py: Deployment information
    • manage.py

Use in command line cd Enter into my_website Catalog , Run the following command again :

python manage.py runserver

Open browser access :http://127.0.0.1:8000/, Get what's shown in the figure below , Express Django Already open .

During operation , You can also specify ports , For example, the following command :

python manage.py runserver 8080

Use Ctrl+C Out of Service .


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