Static files not found in Mezzanine

1k views Asked by At

I am trying to install a new template on my Mezzanine website. My Mezzanine is on version 4.2.2 and Django on 1.9.7 . Here is what I did:

With

DEBUG = true

I created a new app call "template_app" and loaded in settings.py:

INSTALLED_APPS = (
    "template_app",
    ...
)

I created the directory structure, and copied over the default mezzanine files (base, index...) like:

template_app
    static
        css
        img
        js
    templates
        base.html
        index.html
        includes
            footer_scripts.html

I downloaded a bootstrap template and replaced the above css js img folder and index.html with the ones found in the template. (The template I used: https://startbootstrap.com/template-overviews/business-casual/ ) Then link the css and javascript in base.html:

(All css)

{% compress css %}
<link rel="stylesheet" href="{% static "css/bootstrap.css" %}">
<link rel="stylesheet" href="{% static "css/bootstrap.min.css" %}">
<link rel="stylesheet" href="{% static "css/business-casual.css" %}">
<link rel="stylesheet" href="{% static "css/mezzanine.css" %}">
<link rel="stylesheet" href="{% static "css/bootstrap-theme.css" %}">

(All js)

{% compress js %}
<script src="{% static "mezzanine/js/"|add:settings.JQUERY_FILENAME %}"></script>
<script src="{% static "js/bootstrap.js" %}"></script>
<script src="{% static "js/bootstrap.min.js" %}"></script>
<script src="{% static "js/jquery.js" %}"></script>
<script src="{% static "js/bootstrap-extras.js" %}"></script>

I'm not sure where I did wrong, or what I am missing. My website can't find the css and javascript file in the app:

Not Found: /css/bootstrap.min.css/
Not Found: /css/business-casual.css/
[07/Jan/2017 08:12:30] "GET /css/bootstrap.min.css/ HTTP/1.1" 404 1716
[07/Jan/2017 08:12:30] "GET /css/business-casual.css/ HTTP/1.1" 404 1720
Not Found: /js/jquery.js/
...

I tried modify urls.py and other parts of setting.py based on other's solutions, but they don't seems to be working. What am I doing wrong?

-- added 2017-01-09 --

Checking with findstatic linked me to the right path. Except bootstrap.css which linked me both the css file in my downloaded template and the mezzanine template.

3

There are 3 answers

0
BugZap On

I had the same issue with static files, but it did require that I set the "STATIC_ROOT" setting since my paths were off course.

Since I was using a custom theme I had to change the "STATIC_ROOT" path in settings.py to point to my app static files rather than it pointing to the default PROJECT_ROOT.

So I added something like this...

## Custom Theme Path (For Static Files)
THEME_URL = "template_app/"

And Changed "STATIC_ROOT" to...

STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(PROJECT_ROOT, THEME_URL, STATIC_URL.strip("/"))
0
Michel On

Make sure you restart the test server again (manually if need be), the autorestart doesnt recognise changes to the static/ directories.

0
Ramon Melo On

I found this question on Google while looking for a solution for the same issue. I managed to work around with these steps:

  • First of all, double check that template_app is listed on INSTALLED_APPS above all Mezzanine apps;
  • Re-run findstatic;
  • If you still don't find it, run collectstatic. While findstatic wouldn't find the theme I wanted (but would find other themes), collectstatic managed to find it and link its static files.