在我自己的服务器上提供静态文件
我正在设置 django 服务器,但我的静态文件有问题:
django settings
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/'
apache
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
有什么想法吗? 谢谢
im setting a django server, but im having problem with my static's file's:
django settings
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/'
apache
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>
So, i have the admin without style and the website, for example http://localproject/public is showing a error about * Not FlatPage matches the given query *
yes, im using django.contrib.staticfiles
Any idea?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两件事:
首先,
ADMIN_MEDIA_PREFIX = STATIC_URL+'admin/'
。您实际上可以使用它或将其更改为ADMIN_MEDIA_PREFIX = 'http://localproject/static/admin/'
。/static/admin/
在您的场景中不正确。其次,Django 仍在收到请求,并且“public”作为 slug 传递到 FlatPages 视图,这就是您收到该错误的原因。请参阅: https://docs.djangoproject.com/en/ dev/howto/deployment/modwsgi/#serving-files 了解静态文件的正确 Apache 配置。
Two things:
First,
ADMIN_MEDIA_PREFIX = STATIC_URL+'admin/'
. You can actually use that or change it toADMIN_MEDIA_PREFIX = 'http://localproject/static/admin/'
./static/admin/
is incorrect in your scenario.Second, Django is still being handed the request, and 'public' is being passed as a slug to the FlatPages view, which is why you're getting that error. See: https://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/#serving-files for the proper Apache configuration for staticfiles.
我的回答也许对某人有帮助,问题是我使用 apache (/etc/apache2/sites-available/project),但我错了“使用另一个 apache配置到项目中”/srv/www/project/apache/httpd.conf 并在最后一个配置中设置我的别名(当别名配置需要位于(/etc/apache2/sites-available/project)
以及项目内容
我的settings.py:
现在正在工作:),记住这是我自己的服务器
Im answering maybe that help someone, the problem was that im using apache (/etc/apache2/sites-available/project), but i was wrong with "use another apache config into the project" /srv/www/project/apache/httpd.conf and setting my Alias in this last one config, when the Alias config need to be in (/etc/apache2/sites-available/project)
and the content for project
my settings.py:
And now is working :), remember this is my own server