In Django project, for static resource files js, css, images, etc., need a public storage path, or each application to create a new static folder, then there is very convenient.
So how to configure it?
Configure a static file path of settings.py
In STATIC_URL = '/static/'
the following add code
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
Under the new static project root folder and add the following sub-folders and files
File structure is as follows:
Okay, so that a good public static configuration files in the project. Let's continue configuring common template path.
Settings.py configuration template file path
TEMPLATES DIRS set of values as follows:
'DIRS': [os.path.join(BASE_DIR, 'templates')],
Under the project path, create templates folder, and continue to create the application folder name
File structure is as follows:
So after such a configuration template path, application assetinfo how to call it?
View templates way calling application
Because the definition of a good path templates, so you can just write the relative path under templates.
Here then put another front-end code, used to call the static test files.
Another set of front-end code into
You can know just configured the storage path static files, static html file path corresponding code also needs to be modified.
Increase in front of all the static files /static/
path to, the following:
Writing a view of the page display
Then configure the url path, use the following browsers to test and see, as follows:
You can see the page has been successfully demonstrated out.
View page source code, as follows:
We can see a static file is a normal visit.
Reproduced in: https: //www.jianshu.com/p/e8c03c01dc6e