"Python" resolves the loss of the Django Admin Interface style sheet (CSS style)

Source: Internet
Author: User
Tags nginx server

To configure Django Admin, refer to the Django Official document "Activate the Admin site" For information on how to enable it. However, I was in the configuration process login http://example.com/admin background When the style sheet lost problems, such as the interface has become this:

Internet search a lot of documents, more is the Apache environment solution, I configured is Nginx server, so according to Apache solution tips and then explore ways, finally to solve this problem I summarized here there are 3 steps (assuming that the admin login system is configured):

1. Modify the physical path of the static file static_root for you in settings.py , for example, my static file is stored in /home/user/www/static , First create the STATIC folder under the WWW directory, and finally modify settings.py in static_root to point to /home/user/www/static.

2. Run the python manage.py collectstatic Command, which copies the required static files from the Django resource bundle to the static folder Static_root indicated. This includes the style sheets (styles), images, and scripts (JS) that are necessary for the admin interface.

Here is a hint that if you do not take the 1th step, running this command directly will result in the following error message (the last few lines):

  File "/usr/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 41, In __init__    self.storage = get_storage_class (settings. Staticfiles_storage) ()  File "/usr/lib/python2.7/dist-packages/django/contrib/staticfiles/storage.py", line 23 , in __init__    raise improperlyconfigured ("You ' re using the Staticfiles app" Django.core.exceptions.ImproperlyConfigured:You ' re using the Staticfiles app without having set the Static_root setting.

In fact already prompted to configure the Static_root file (you ' re using the Staticfiles app without have set the Static_root setting).

3. Modify the Nginx configuration, /etc/nginx/nginx.conf or /etc/nginx/sites-enabled/ configuration files under the Debian system, Add the following in the server section (please modify it as appropriate):

server {  # ... The rest of the content is slightly  location/static {      root/home/user/www;  }}

If I don't change it here, I'll test it and it looks like the default processing will be handed to Django, but it will still be prompted by Django Page not found (404).

After completing the three steps above, reload the appropriate settings:

INVOKE-RC.D Uwsgi Reloadnginx-s Reload

Well, basically the problem is solved, if there is anything inappropriate in the place to welcome the point.

Resources:

http://wangye.org/blog/archives/572/

"Python" resolves the loss of the Django Admin Interface style sheet (CSS style)

Related Article

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.