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