[Django] configuration of Django's css, image, and js static file production environment, djangocss

Source: Internet
Author: User

[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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.