【问题标题】:Pyramid - fanstatic application cannot find static resources under apache wsgi modulePyramid - fanstatic 应用程序在 apache wsgi 模块下找不到静态资源
【发布时间】:2014-07-27 21:04:42
【问题描述】:

我有一个使用 pcreate 创建的 Pyramid-Fanstatic 应用程序:

pcreate -s starter -s pyramid_fanstatic

如果我使用 /bin/pserve-fanstatic 启动服务器,一切正常。但是,当我使用 Apache WSGI 模块加载应用程序时,会出现如下链接:

<link rel="stylesheet" type="text/css" href="/fanstatic/services/bootstrap/bootstrap.min.css" />

返回 404 Not Found by Apache。

这是我的 WSGI 应用程序:

import os
activate_this = os.path.join('/opt/services/services/bin/activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
os.environ['PYTHON_EGG_CACHE'] = '/opt/services/python-eggs'


from pyramid.paster import get_app, setup_logging
ini_path = '/opt/services/services/development.ini'
setup_logging(ini_path)
application = get_app(ini_path, 'main') 

这是我的 Apache 配置文件:

<VirtualHost *:80>
    ServerAdmin a.orth@cgiar.org
    ServerName data.ilri.org

    # Pass authorization info on (needed for rest api).
    WSGIPassAuthorization On

    WSGIDaemonProcess services python-path=/opt/services/services display-name=services processes=2 threads=15
    WSGIScriptAlias /services /opt/services/services/services/services.wsgi process-group=services application-group=%{GLOBAL}

    <Location /services>
                WSGIProcessGroup services
    </Location>

    ErrorLog /var/log/httpd/services.error.log
    CustomLog /var/log/httpd/services.custom.log combined

</VirtualHost>

我可以看到 /bin/pserve-fanstatic 在加载应用程序之前包含了我的资源目录:

"""A script aware of static resource"""
    import pyramid.scripts.pserve
    import pyramid_fanstatic
    import os

    dirname = os.path.dirname(__file__)
    dirname = os.path.join(dirname, 'resources')
    pyramid.scripts.pserve.add_file_callback(
                pyramid_fanstatic.file_callback(dirname))
    pyramid.scripts.pserve.main()

但即使我在我的 init.py 中包含这些行,Apache 也无法找到 fanstatic 资源。

我也将此添加到我的 ini 文件中:

[filter:fanstatic]
use = egg:fanstatic#fanstatic

[pipeline:main]
pipeline = fanstatic services

我还应该检查/做什么?

【问题讨论】:

    标签: python apache mod-wsgi pyramid fanstatic


    【解决方案1】:

    您似乎没有告诉 Apache 提供您的静态文件。见:

    【讨论】:

    • 是的,我通读了它,尝试了一些东西,但最后是我在回答中指出的 ini 文件中的一些配置。
    【解决方案2】:

    已修复!!

    我必须在 [app:main] 的 ini 文件中添加这一行:

    fanstatic.publisher_signature = fanstatic
    fanstatic.use_application_uri = true
    

    根据文档:https://pypi.python.org/pypi/pyramid_fanstatic

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-14
      • 2011-02-24
      • 2011-12-11
      • 1970-01-01
      • 2019-11-16
      • 2017-01-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多