Do one thing at a time, and do well
Do one thing at a time, do your best!
Too much introductory content will not be written. I mainly want to say to the students who are entangled in django or flask and even other frameworks. The framework of learning is not important. It is like learning a language, and it is a door-to-door. Whether Django or flask is very powerful, it is enough for us to write a project.
Django is designed using the MVC framework, but more accurately it should be based on the MTV framework, which is a model-view-template. Briefly, the model is the database (responsible for data storage), the view is the back end (responsible for data processing), the template is the front end (responsible for data display), the model and view in Django correspond to models.py, views.py, and the template You need to create an html file in the templates directory, and the functions in views.py render the Html template in the templates to get the dynamic content of the page.
The search function of a Django page, the whole process is like this: get user input from the template —> request to the view —> view to get data from the model —–> view to process the data —– > Return to the model display.
Description: It is recommended to build django using the Python virtual environment.
New project and app:
Use the built-in server:
Create an administrator:
Data import and export:
Project environment terminal:
Description: The api in the models.py of the current project can be called from this shell.
Database command line:
You can execute the sql statement on the command line.
Note: The directory cannot have Chinese.
Turn on the built-in server:
There can be multiple applications in a project, one application is a web application.
Description: A webapp folder will be created in the same directory as manage.py.
Add the newly defined app, here the webapp to setting.py:
Description: Adding the app is for django to know that we created a new app that will load the app.
Define the view function (views.py):
Description: The view function (view.py) is a function of some column functions done on the server side. It receives a request request and returns a response.
Define the url and modify urls.py:
Description: urls.py is a file that defines django routes. This route is not a route in the network. In short, it is a url. It defines which functions in the view are executed when we request which urls.
- This article only makes the most basic Django introduction. As for the specific usage of each layer of MVC and the configuration, security, deployment and other issues, it will be introduced one by one.