Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy aren't static assets loading when I access my pyramid app through my computer's IP address?
    primarykey
    data
    text
    <p>I have a Pyramid app that I've been developing and viewing locally through <code>http://localhost:6543</code>, which is what the paster docs suggest. There are various assets, for example <code>.css</code> files, available in a <code>static</code> directory, which I have made available through <code>config.add_static_view('static','static')</code> When I view it through <code>localhost</code> everything works fine, my .css files are loaded, and all is well. However, when I view the app through my computer's hostname/IP address, the static assets aren't loaded.</p> <p>A freshly-installed Pyramid paster scaffold displays the same behavior. I've gone through and followed the Pyramid narrative documentation through the step called <a href="http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/project.html#viewing-the-application" rel="nofollow">viewing the application</a>, and everything works as is described. But change the URL in the location bar from <code>http://localhost:6543</code> to <code>http://my.host.name:6543</code> and the style sheets don't get loaded. </p> <p>The assets are available; type <code>http://my.host.name:6543/static/pylons.css</code> on a freshly-created Pyramid paster scaffold and you can read the contents of the css, but it's not loaded when the root page is loaded. Firebug indicates that those resources are requested, but never received. </p> <p>What's going on here, and how can I make sure that my static assets are loaded when I request them through something other than <code>localhost</code>?</p> <p><strong>Edit</strong> to add some code. This is from the Pyramid <code>starter</code> paster scaffold, which I haven't modified and which exhibits the same behavior my application does; it can be considered a minimal example.</p> <p>from package's <code>__init__.py</code>:</p> <pre><code>def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ config = Configurator(settings=settings) config.add_static_view('static', 'static', cache_max_age=3600) config.add_route('home', '/') config.scan() return config.make_wsgi_app() </code></pre> <p>complete <code>views.py</code>:</p> <pre><code>from pyramid.view import view_config @view_config(route_name='home', renderer='templates/mytemplate.pt') def my_view(request): return {'project':'TestProject'} </code></pre> <p>relevant line from <code>templates/mytemplate.pt</code>:</p> <pre><code>&lt;link rel="stylesheet" href="/static/pylons.css" type="text/css" media="screen" charset="utf-8" /&gt; </code></pre> <p>Where <code>static/pylons.css</code> is in the <code>static</code> directory under the root.</p> <p>Again, opening <code>http://0.0.0.0:6543</code> in the browser (FF10) works fine, <code>http://my.host.name:6543</code> displays the page without style information; but <code>http://my.host.name:6543/static/pylons.css</code> gives me the style sheet text.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload