Settings. py

Source: Internet
Author: User

In settings. py: HERE = OS. path. dirname (OS. path. dirname (_ file _) MEDIA_ROOT = OS. path. join (HERE, 'Media '). replace ('\', '/') MEDIA_URL = '/media/' STATIC _ ROOT = OS. path. join (HERE, 'static '). replace ('\', '/') STATIC_URL = '/static/'admin _ MEDIA_ROOT ='/static/ADMIN/'staticfiles_dirs = (OS. path. join (HERE, 'app1/static /'). replace ('\', '/'), OS. path. join (HERE, 'app2/static /'). replace ('\', '/') In urls. py add these codes: from django. conf import settingsfrom django. conf. urls. static import staticurlpatterns + = static (settings. MEDIA_URL, document_root = settings. MEDIA_ROOT) urlpatterns + = static (settings. STATIC_URL, document_root = settings. STATIC_ROOT) in templates: {% load static %} www.2cto.com <link href =" {get_static_prefix} css/truple.css/> very important several paragraphs: 1. # Don't put anything in this directory (STATIC_ROOT) yourself; store your static files in apps '"static/" subdirectories and in STATICFILES_DIRS. 2.The most likely example is user-uploaded content in MEDIA_ROOT. staticfiles is intended for static assets and has no built-in handling for user-uploaded files, but you can have Django serve your MEDIA_ROOT by appending something like this to your URLconf: urlpatterns + = static (settings. MEDIA_URL, document_root = settings. MEDIA_ROOT)

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.