我在django中遇到静态文件的问题。应用程序出现,但没有静态文件。 我做了collecstatic命令。
我使用apache,下面是虚拟主机站点 - 可用目录
我的虚拟主机:
<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/'
答案 0 :(得分:0)
将以下内容添加到您的conf
<Directory /home/prod/www/myapp/myapp/staticfiles>
Require all granted
</Directory>