Django uses local css/js files

Source: Internet
Author: User

Read a lot online about how Django uses local css/js, but it doesn't work.

Today, we finally found a way to use it, record it.

Create a static folder at the same level of manager.py with CSS, JS, image, and other files or folders

My folder hierarchy

Then it's simple, just set it in settings.py and add the following code at the end.

Static_url ='/static/' Here=Os.path.dirname (Os.path.abspath (__file__)) here= Os.path.join (Here,'.. /') Staticfiles_dirs=(# Put strings here, like"/home/html/static"Or"c:/www/django/static".    # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths.Os.path.join (Here,'static/'),)

In the HTML file that you want to use, import it in the following way

<!--introduce local CSS & js-->        <link rel="stylesheet" href=". /static/style/medicine.css" />        <script type="text/javascript" src=". /static/javascript/medicine.js"></script>

Django uses local css/js files

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.