即时设置django服务器,但我的静态文件有问题:
STATIC_URL = 'http://localproject/static/'
STATIC_ROOT = '/srv/www/project/static/'
MEDIA_ROOT = '/srv/www/project/public/'
MEDIA_URL = '/public/'
ADMIN_MEDIA_PREFIX = '/static/admin/'
Alias /static/ /srv/www/project/static/'
<Document /srv/www/project/static>
Order allow,deny
Allow form all
</Document>
Alias /public/ /srv/www/project/public/'
<Document /srv/www/project/public>
Order allow,deny
Allow form all
</Document>
所以,我有没有样式的管理员和网站,例如http://localproject/public显示错误 * Not FlatPage匹配给定的查询*
是的,我正在使用django.contrib.staticfiles
有什么想法吗? 感谢
答案 0 :(得分:0)
两件事:
首先,ADMIN_MEDIA_PREFIX = STATIC_URL+'admin/'
。您实际上可以使用它或将其更改为ADMIN_MEDIA_PREFIX = 'http://localproject/static/admin/'
。您的方案中/static/admin/
不正确。
其次,Django仍然被提交请求,并且'public'作为slug传递给FlatPages视图,这就是为什么你得到了这个错误。有关静态文件的正确Apache配置,请参阅:https://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/#serving-files。
答案 1 :(得分:0)
我回答也许是帮助某人,问题是我使用apache (/ etc / apache2 / sites-available / project) ,但我错了& #34;在项目中使用另一个apache配置&#34; /srv/www/project/apache/httpd.conf 并在最后一个配置中设置我的别名,当Alias配置需要在 中时(/ etc / apache2 / sites-available / project)
using:$ sudo nano /etc/apache2/sites-available/project
和项目内容
<VirtualHost *:80>
ServerName project
DocumentRoot /srv/www/project
<Directory /srv/www/project>
Order allow,deny
Allow from all
</Directory>
AliasMatch ^/([^/]*\.css) /srv/www/project/static/css/$1
Alias /public/ /srv/www/project/public/
Alias /static/ /srv/www/project/productos/static/
<Directory /srv/www/project/productos/static>
Order deny,allow
Allow from all
</Directory>
<Directory /srv/www/project/public>
Order deny,allow
Allow from all
</Directory>
WSGIDaemonProcess project processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup project
WSGIScriptAlias / /srv/www/project/apache/django.wsgi
</VirtualHost>
我的settings.py:
MEDIA_ROOT = '/srv/www/project/public/'
MEDIA_URL = 'http://project/public/'
STATIC_ROOT = '/srv/www/project/productos/static/'
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = 'http://project/static/admin/'
现在正在工作:),记住这是我自己的服务器