Static files cannot be accessed After Django disables debug.

Source: Internet
Author: User
Tags django server

The Django framework only provides static file services in development mode. When I enable the debug mode, the built-in Django server provides the static file service, so there is no problem with CSS and other file access, but after the debug mode is disabled, django does not provide static file services. Think about this. This is in line with Django's philosophy: The standard servers are very good at this part. Let the servers do it!

OK, the solution to the problem also appeared. The first thing I thought of was that the configuration used for official project deployment was provided by Apache for static file service. However, there are far more than one method to solve the problem. On stackoverflow, I found a more interesting method. The following table lists the four methods you have summarized. For details, refer:

1. Provide the file service for static files by Apache (similar to official deployment ):

Alias/static // opt/path/static/

2. Use Django. Views. Static. Serve. Add the following in urlconf:

(R' ^ site_media /(? P <path>. *) $ ', 'django. Views. Static. serv', {'document _ root':'/path/to/media '}),

This method is evaluated in official documents: "the big, fat disclaimer ".

3. forge a 404 page: use the correct URL to link the 404 page template;

4. Change the project running mode:

Python manage. py runserver -- insecure

Finally, this is the most popular method on stackoverflow, which is really simple and quick!

 

From: http://my.oschina.net/zyzzy/blog/173262

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.