Django admin has no style

后端 未结 2 892
孤城傲影
孤城傲影 2020-12-16 23:25

I have just moved my django site on my staging server, and the admin side of the site has no styling with it, when previously in local development it was fine, I read somewh

相关标签:
2条回答
  • 2020-12-16 23:31

    Depending on your web server setup, you can do it one of two ways:

    Symlinking

    In your website's root folder, you should create a symbolic link to your Django admin media directory, with the name name as the ADMIN_MEDIA_PREFIX in your Django app's settings. By default this is /media/, so in your web root folder, create a symlink called media to /usr/lib/python2.5/site-packages/django/contrib/admin/media. (Note the trailing media on the end of the symlink, which is missing from your own example -- the Django admin media is located in a media subdirectoryincontrib/admin`).

    Apache Alias

    If your production server is Apache, and you can change the root configuration, you can use mod_alias to set up the path to Django admin media. Again, assuming that your ADMIN_MEDIA_PREFIX is /media/, you can set up an alias like so:

    <VirtualHost *:80>
      Alias /media/ /usr/local/lib/python2.5/site-packages/django/contrib/admin/media/
    </VirtualHost>
    

    This way, all requests under the path /media/ will be resolved to that directory.

    A similar technique exists for most other servers, such as Lighttpd or nginx; consult your server's documentation if you don't use Apache.


    The solution using Apache's mod_alias is probably best for deployment, but the symlinking approach works just as well too.

    The reason your app worked on your staging server is most likely because it was running with Django's internal web server, which can automatically resolve the path to the admin media directory.

    0 讨论(0)
  • 2020-12-16 23:48

    I think you've created the symlink the wrong way round - your command has created a htdocs symlink in ..../contrib/admin/

    What you need is something like

    sudo ln -s /usr/lib/python2.5/site-packages/django/contrib/admin/ /var/www/sico/htdocs/X
    

    Where X is whatever you need to get to your ADMIN_MEDIA_PREFIX. I think the default would be admin/media

    Hope that helps

    0 讨论(0)
提交回复
热议问题