In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the basic knowledge points of Django". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the basic knowledge points of Django".
Static file
1.1 what is a static file first?
We call these css,js,images static files.
1.2 use of static files
We need to first create a folder for static, which is juxtaposed with our application.
Then create a css,js,images folder under the static folder.
1.3 configure
Configure in our settings.py and add two configurations:
# set the url corresponding to accessing static files, which is generally written as static, of course, it can also be written as other
# and it has nothing to do with the static folder static we just created.
STATIC_URL ='/ static/'
# set the physical directory where the static files are located
# this setting has been given to the directory of static files, so the STATIC_URL above is the same as the one we created ourselves
# static folder irrelevant
STATICFILES_DIRS = [os.path.join (BASE_DIR,'static')]
1.4. Loading order of static files
First of all, go to our own configured path STATICFILES_DIRS, and go down to find the picture. If you can't find it, he will go back to the static under our application to find it. (none of our applications have created static)
1.5. Example
We need to display a picture in the template.
This starts with static and has something to do with the STATIC_URL we set up. It starts with our static files and has nothing to do with our key static folder.
1.6. Dynamically load pictures
What is a dynamically loaded picture? last time we talked about a dynamically loaded url. It's the same here. We don't write down the path of the picture.
You need to write something like this on the template page:
# first you need to load the configuration
{% load staticfile%}
# load pictures dynamically
Middle ware
What is middleware?
The function interface reserved for us in the Django framework is before the execution of the view function, that is to say, the browser sends a request, which used to directly request a method in the view, but now there is an additional method in the middle to interfere with the request and reply.
First of all: we need to create a middleware.py file under the application.
We create a class in it:
Class TestMiddleware (object).
We usually end with Middleware for the class, then we need to register the class in the settings.py file, find the MIDDLEWARE_CLASSES option, and add the 'application name .accounleware.TestMiddleware' to register. Then you need to define the function in it.
The functions reserved for us by Django:
_ _ init__: is called on the first request of the server
Process_request: called before url enters the match
Process_view: called before the view function is called
Process_response: after the view function is called, before returning to the server
Process_exception: this function will be called if an exception occurs in the view function
After knowing the function reserved for us by Django, we can use it.
These parameters and function names are fixed.
Admin background management
1. Time, language localization
In settings.py: LANGUAGE_CODE = 'zh-hans'
TIME_ZONE='Asis/Shanghai'
2. Create a Super Admin
3. Register the model class
4. Custom model class attributes:
Class name (admin.ModelAdmin):
# if there is too much data
# display 10 pieces of data per page
List_par_page = 10
# display multiple title per line
List_display = ['id','xxx','xxxxx']
# add filter column
List_filter = ['id'] # use id as the filter bar
# add search box
Search_fields = ['id'] # search according to id
Thank you for your reading, these are the contents of "what are the basic knowledge points of Django". After the study of this article, I believe you have a deeper understanding of what are the basic knowledge points of Django, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.