Static file path configuration for Django1.4 and 1.3
Source: Internet
Author: User
In Django, there are two files to modify for the routing configuration (static file path configuration):
Generally we will put all the static files in a folder, so now we want to create a new static directory under the project directory, and then the site needs to use the static files: CSS, pictures, JS and so on all in the static directory.
Note: The Django1.4 and 1.3 configuration methods are small and different
Static file path configuration in Django1.4
Added in 1,urls.py:
URL (r ' ^static/(? P . *) $ ', ' django.views.static.serve '),
This is handled using Django's own static file server, which is not needed after deployment to the production environment.
2,settings.py
Let's take a look at the static file path configuration for Django1.3:
1. Set the static file path
We want to set a static file path Static_path in the settings.py file, which is the directory where we just stored the static file. To avoid writing the path, we can use some of the methods in the OS module to convert the absolute path, adding the following code to the settings.py file:
Import OS
Your_path=lambda *x:os.path.join (Os.path.abspath (Os.path.dirname (__file__)), *x)
Static_path=your_path (' static ')
This static_path we are going to use when configuring URLs.
Of course the urlconf in the "static" we can use other names, according to the convention we generally use "static"
Finally, one thing to note: And now if we want to use the static file in the template file, we can call it normally. Be aware that the beginning of the path is prefixed with "/"
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.