Question

I love Django but getting static files served in development is painfully flakey. I have installed webassets to make the job easier. Basically, my assets are 404'ing with my current configuration but admin assets are fine (?!). My project layout is like this;

myapp/
    common/
        static/
            bootstrap/
                img/
                less/
                js/
        templates/
        __init__.py
        assets.py
        urls.py
        models.py
        views.py
    projects/
        templates/
        static/
        __init__.py
        assets.py
        urls.py
        models.py
        views.py
    public/ <- (static files collected here)
settings.py

In my settings I have the following values configured

__DIR__ = os.path.abspath(os.path.dirname(__file__))
MEDIA_ROOT = os.path.join(__DIR__, 'media')
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(__DIR__, 'public')
STATIC_URL = '/static/'

My urls are configured like this;

urlpatterns = patterns('',
    url(r'^projects/', include('myapp.projects.urls')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', include('myapp.common.urls')),
)

urlpatterns += staticfiles_urlpatterns()

Again, assets.py looks pretty standard;

from django_assets import register, Bundle

js = Bundle(
    'bootstrap/js/bootstrap-alert.js',
    'bootstrap/js/bootstrap-button.js',
    'bootstrap/js/bootstrap-carousel.js',
    'bootstrap/js/bootstrap-collapse.js',
    'bootstrap/js/bootstrap-modal.js',
    'bootstrap/js/bootstrap-popover.js',
    'bootstrap/js/bootstrap-scrollspy.js',
    'bootstrap/js/bootstrap-tab.js',
    'bootstrap/js/bootstrap-tooltip.js',
    'bootstrap/js/bootstrap-transition.js',
    'bootstrap/js/bootstrap-typeahead.js',
    output='bootstrap/script.js',
    debug=False
)

register('js', js)

And my base template is very basic;

{% load assets %}
{% assets 'js' %}
    <script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %}

So, when runserver is running, all the js files are bundled into 1 tag with the following url http://localhost:8000/static/bootstrap/script.js?ed501ad2. But this 404's with the message "'bootstrap/script.js' could not be found".

If however, I log into the /admin app then all css assets are rendered correctly. I've run collectstatic and verified that the assets does actually live within public/ directory.

What am I missing here?

Was it helpful?

Solution

Did you add django_assets.finders.AssetsFinder to your STATICFILES_FINDERS as is required in the document of django-assets?

http://elsdoerfer.name/docs/webassets/django/index.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top