Django管理网站不显示CSS样式 [英] Django admin site not showing CSS style

查看:402
本文介绍了Django管理网站不显示CSS样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Django管理员网站(这是完全默认的,不是自定义的)没有显示预期的CSS。

My Django admin website (it's completely default, not customized) is not showing the expected CSS.

它看起来像这样:

我可以登录:

但它应该是这样的:

如何解决这个问题?

可能有帮助的其他信息:

我正在80端口上的Amazon EC2实例上运行,并连接使用真实的URL。我使用本教程进行设置:
http:/ /www.nickpolet.com/blog/deploying-django-on-aws/1/

I'm running on an Amazon EC2 instance on port 80 and connecting to it using a real URL. I set it up using this tutorial: http://www.nickpolet.com/blog/deploying-django-on-aws/1/

在该教程之后,我将此代码放入一个名为 /etc/apache2/sites-enabled/mysite.conf 。我不明白这段代码正在做什么,所以我认为这可能与问题有关。

Following that tutorial, I put this code into a file called /etc/apache2/sites-enabled/mysite.conf. I don't understand what this code is doing, so I think it might be related to the problem.

/ etc / apache2 / sites-enabled / mysite .conf:

WSGIScriptAlias / /home/ubuntu/cs462/mysite/mysite/wsgi.py
WSGIPythonPath /home/ubuntu/cs462/mysite
<Directory /home/ubuntu/cs462/mysite/mysite>
    <Files wsgi.py>
        Order deny,allow
        Require all granted
    </Files>
</Directory>

Alias /media/ /home/ubuntu/cs462/mysite/media/
Alias /static/ /home/ubuntu/cs462/mysite/static/

<Directory /home/ubuntu/cs462/mysite/static>
    Require all granted
</Directory>

<Directory /home/ubuntu/cs462/mysite/media>
    Require all granted
</Directory>

目录结构

/home/ubuntu/cs462/
        mysite/
            manage.py
            db.sqlite3
            mysite/
                __init__.py
                __init__.pyc  
                settings.py  
                settings.pyc  
                urls.py  
                wsgi.py
            homepage/
                admin.py  
                admin.pyc  
                __init__.py  
                __init__.pyc  
                migrations  
                models.py  
                models.pyc  
                tests.py  
                views.py

最后一部分settings.py:

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/

STATIC_URL = '/static/'


推荐答案

您的Apache配置要求所有静态内容(CSS,JS,图像等) )应该在mysite / static目录下。您应该将静态内容从应用程序中收集到mysite / static目录中:

Your Apache configuration requires that all static content (CSS, JS, images etc) should be in the mysite/static directory. You should collect your static content from apps into the mysite/static directory first:

cd /home/ubuntu/cs462/mysite
python manage.py collectstatic

更新:如果您没有为静态内容指定位置,您应该将以下行添加到您的 settings.py 中:

Update: If you did not specify a location for static content, you should add the following lines to your settings.py:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

这篇关于Django管理网站不显示CSS样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆