Django Project deployed in Apache server, static file path Note point

Source: Internet
Author: User

The path of the Django Apache deployment static file Note point

Static files are placed in the static folder under the corresponding app or in a folder in Staticfiles_dirs.

When DEBUG = True, Django can automatically find the static files that are placed inside. (Django uses the "finder" in Staticfiles_finders to find a match and then stops, looking for a process similar to the one in Python when using import XXX to find the XXX package).

When we have finished deploying the project, the value of debug is changed to False, and we need to use a public static folder to hold the static file.

Example Project Dj18static, there is a static inside the app app with a zqxt.png image:

dj18static├── blog│   ├── __init__.py│   ├── admin.py│   ├── migrations│   │   └── __init__.py│   ├── models.py│   ├── static # 应用 blog 下的 static, 默认会找这个文件夹│   │   └── 【zqxt.png】│   ├── tests.py│   ││   └── views.py├── common_static # 已经添加到了 STATICFILES_DIRS 的文件夹│   └── js│       └── 【jquery.js】│├── dj18static│   ├── __init__.py│   ├── settings.py│   ├── urls.py│   └── wsgi.py└── manage.py

When DEBUG = True in settings.py, open the development server Python manage.py runserver direct access to/static/zqxt.png to find this static file.

You can also specify static files that are common to all apps, such as Jquery.js, in settings.py

Staticfiles_dirs = (Os.path.join (base_dir, "common_static"), put Jquery.js under common_static/js/so that it can be/static/js/ Jquery.js in the access to it!

When debugging with Runserver, static files are placed in the static folder within the app to access them.

However, when the project is deployed in the Apache server, it is necessary to create the common static folder common_static and the manage.py sibling after configuring the Apache server's project path and the static file path, and copy the static files inside the app into the public static folder.

Django Project deployed in Apache server, static file path Note point

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.