[Django] configuration of Django's css, image, and js static file production environment, djangocss
In Django, if HTML files introduce css, js files, or image images in external ways, <link rel = "stylesheet" href = ".. /css/lstyle.css "> This format can be used only when it is configured in django.
Keywords: django static file django production environment django1.8
Body:
Step 1: Create a static folder under the django project directory, and create three folders with different names under the static folder to store css and js static files and image images.
Step 2: Find the settings. py configuration file and modify it as follows:
STATIC_URL = '/static /'
STATICFILES_DIRS = (
OS. path. join (BASE_DIR, "static "),
)
After the configuration is completed, the following applications are available in the html file:
{% Load staticfiles %} # The html file header must be added before the following call can take effect.
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html>
<Head>
<! -- Basic Page Needs
========================================================== ============ -->
<Meta charset = "UTF-8">
<Title> </title>
<Meta name = "description" content = "! ">
<Meta name = "keywords" content = "">
<Meta name = "author" content = "CQ_LQJ">
<! -- CSS
========================================================== ============ -->
<Link rel = "stylesheet" href = "{% static 'css/style.css '%}"> # method 1
<Link rel = "stylesheet" href = "/static/css/style.css"> # method 2
</Head>
<Body>
</Body>
</Html>