1

I tried the following (accepted answer) at: Django static files on heroku But did not seem to work.

The issue is that whilst the path to seems to be correct, I cannot get the correct behaviour when displaying the template html. I'm trying to load the jquery library and a table sorter. If I try the actual location: www.mydomain.com/static/javascript/jquery.tablesorter.js it accesses fine. But in the template which has the following, I get no value for {{staticvalues}} or {{static}}.

Here is the template:

{% load staticfiles %}

files: {{ staticfiles }}
files: {{ static }}

<script type="text/javascript" src="{% static "/javascript/jquery-1.11.2.min.js" %}"></script> 
<script type="text/javascript" src="{% static "/javascript/jquery.tablesorter.js" %}"></script>

<table id="myTable" class="tablesorter"> 

Here is my urls.py:

from django.conf.urls import patterns, include, url
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.contrib import admin
admin.autodiscover()
import hello.views
from diy import settings

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'diy.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^$', hello.views.index, name='index'),
    url(r'^db', hello.views.db, name='db'),
    url(r'^admin/', include(admin.site.urls)),

)


urlpatterns += patterns('',
        (r'^static/(?P<path>.*)$', 'hello.views.static.serve', {'document_root': settings.STATIC_ROOT}),
    )

settings.py:

STATIC_URL = '/static/'
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

Looking at the log files, I find the following:

2015-01-27T18:12:36.780895+00:00 heroku[router]: at=info method=GET path="/javascript/jquery.tablesorter.js" host=xx.herokuapp.com request_id=47d2671b-7905-46cd-8786-817c063051e9 fwd="xx" dyno=web.1 connect=1ms service=51ms status=404 bytes=2555
2015-01-27T18:12:36.817026+00:00 heroku[router]: at=info method=GET path="/javascript/jquery-1.11.2.min.js" host=xxx.herokuapp.com request_id=a4619d34-f76b-4ceb-970a-ab6008585410 fwd="xx" dyno=web.1 connect=1ms service=67ms status=404 bytes=2552

As you'd expect if {{static}} is empty. I tried the following change to the template and found the problem does not resolve, however I get the status=200. Should I not use {{static}} for the static location in the template?

Community
  • 1
  • 1
disruptive
  • 5,687
  • 15
  • 71
  • 135

0 Answers0