当前位置:网站首页>8. Static file
8. Static file
2022-07-06 04:33:00 【Suyuoa】
Like a picture ,css,js, Audio , Video these are static files
Catalog
1 Configuration of static files
3 Use static files in templates
1 Configuration of static files
The configuration of static files is in setting.py Here

This is the default value after the project is created , It can be changed, but it is not necessary
Then we will join STATICFILES_DIRS This variable , This is the storage path for static files , We write like this

- There can be multiple , Here we only use one
Then we create a folder under the project path static, For storing static files

stay static Under the directory, we can create different folders according to different types of static files , such as

2 Accessing static files
Now let's make a map static/picture in

Then we can visit it directly in the browser

Find that you can access , Let's use this image through views and templates
3 Use static files in templates
We use img label
First, make a template , We call it static_picute, Then we write

The above is the absolute path , The following is the relative path , Static files can be called multiple times in the template
Then add the view

Finally, add routing

Then we visit

The above two are html Writing , Now let me say something django Special writing in ——static label , We write this in the template

- There is a prompt red line, but it does not delay the use
Let's visit

Generally speaking, we use static label , In this way, when we need to change later, we need to change less
边栏推荐
- Solve the compilation problem of "c2001: line breaks in constants"
- How many of the 10 most common examples of istio traffic management do you know?
- CertBot 更新证书失败解决
- 11. Intranet penetration and automatic refresh
- Lambda expression learning
- 关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解
- word封面下划线
- About some basic DP -- those things about coins (the basic introduction of DP)
- The most detailed and comprehensive update content and all functions of guitar pro 8.0
- Figure application details
猜你喜欢

In depth MySQL transactions, stored procedures and triggers

Ue5 small knowledge points to enable the setting of lumen

10個 Istio 流量管理 最常用的例子,你知道幾個?

Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code

R note prophet

JVM garbage collector concept

The implementation of the maize negotiable digital warehouse receipt standard will speed up the asset digitization process of the industry

ETCD数据库源码分析——etcdserver bootstrap初始化存储

Certbot failed to update certificate solution

Overturn your cognition? The nature of get and post requests
随机推荐
Basic explanation of turtle module - draw curve
After learning classes and objects, I wrote a date class
Mixed development of QML and QWidget (preliminary exploration)
MySQL reported an error datetime (0) null
10個 Istio 流量管理 最常用的例子,你知道幾個?
2/12 didn't learn anything
QML和QWidget混合开发(初探)
P3500 [poi2010]tes intelligence test (two points & offline)
View 工作流程
Tengine kernel parameters
Canal synchronizes MySQL data changes to Kafka (CentOS deployment)
牛顿插值法
Database - MySQL storage engine (deadlock)
Implementation of knowledge consolidation source code 1: epoll implementation of TCP server
Dynamic programming (tree DP)
729. 我的日程安排表 I(set or 动态开点线段树)
2327. Number of people who know secrets (recursive)
Figure application details
Recommendation system (IX) PNN model (product based neural networks)
Word cover underline