在我自己的服务器上提供静态文件

发布于 2024-12-08 06:37:39 字数 806 浏览 1 评论 0原文

我正在设置 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瑕疵 2024-12-15 06:37:39

有两件事:

首先,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 to ADMIN_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.

少女净妖师 2024-12-15 06:37:39

我的回答也许对某人有帮助,问题是我使用 apache (/etc/apache2/sites-available/project),但我错了“使用另一个 apache配置到项目中”/srv/www/project/apache/httpd.conf 并在最后一个配置中设置我的别名(当别名配置需要位于(/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/'

现在正在工作:),记住这是我自己的服务器

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)

using:$ sudo nano /etc/apache2/sites-available/project

and the content for 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>

my 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/'

And now is working :), remember this is my own server

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文