【问题标题】:Static files do not show up in the Django app静态文件不显示在 Django 应用程序中
【发布时间】:2015-03-06 15:17:31
【问题描述】:

我对 django 中的静态文件有疑问。应用程序出现,但没有静态文件。 我做了集体命令。

我用的是apache,下面是一个虚拟主机sites-available目录

我的虚拟主机:

<VirtualHost *:80>
        ServerName myapp.example.com
        DocumentRoot /home/prod/www/myapp/myapp
        ExpiresActive On
        ExpiresDefault "access plus 0 seconds"

        # Django statics, MEDIA_URL
        Alias /media/ /home/prod/www/myapp/myapp/MyBlog/media
        Alias /static/ /home/prod/www/myapp/myapp/staticfiles

        <Directory /home/prod/www/myapp/myapp>
            Options +FollowSymLinks -Indexes
            AllowOverride AuthConfig
            Order allow,deny
            Allow from all

            ExpiresByType text/css "access plus 1 day"
            ExpiresByType text/javascript "access plus 1 day"
            ExpiresByType image/gif "access plus 1 day"
            ExpiresByType image/jpg "access plus 1 day"
            ExpiresByType image/png "access plus 1 day"
            ExpiresByType application/x-shockwave-flash "access plus 1 day"
        </Directory>

        RewriteEngine on
        ProxyPreserveHost On

        RewriteRule ^/media/.* - [L]
        RewriteRule ^/static/.* - [L]
        #RewriteRule ^/favicon\.ico - [L]

        RewriteRule ^(.*) http://127.0.0.1:48036$1 [P]

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

</VirtualHost>

当我执行print STATIC_ROOT 时,我得到:

 /home/prod/www/myapp/myapp/staticfiles

我的静态网址设置为:

STATIC_URL = '/static/'

【问题讨论】:

    标签: django apache static django-staticfiles


    【解决方案1】:

    将以下内容添加到您的 conf 中

    <Directory /home/prod/www/myapp/myapp/staticfiles>
        Require all granted
    </Directory>
    

    【讨论】:

    • 不适用于此设置。也许有帮助,我的网址:http://myapp.exaple.com/static/js/bootstrap.js
    • /home/prod/www/myapp/myapp/staticfiles 有什么东西吗?
    • 具体在js目录下面。
    • 这很有帮助,因为您不会收到未经授权的 403。你能显示那个目录的ls吗?
    • @C.B.我的静态文件目录:admin css debug_toolbar fonts images js sass
    猜你喜欢
    • 2021-11-03
    • 2020-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-01
    • 2016-10-19
    • 2019-08-19
    • 2012-02-21
    相关资源
    最近更新 更多