0

Perhaps this is a laughable problem but am really lost. It was working fine until I ported the project to a new laptop. Here is my filesystem structure:

bill
   ==>bill (contains settings.py)
   ==>static
   ==>welcome
   ==>manage.py

Now in static i have my directory, i have folder plugins, js and css. The following are in my base.html template:

 <!DOCTYPE html>
 {% load staticfiles %}
 <html lang="en">
 <head>
  <title>{% block ownername %}{% endblock %} {% block title %}{% endblock  %}</title>

<script src="{% static 'plugins/jQuery/jquery-2.2.3.min.js' %}"></script>

 <!-- Bootstrap 3.3.6 -->
<link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.min.css' %}">
 <link rel="stylesheet" href="{% static 'plugins/datepicker/datepicker3.css' %}">

**<link rel="stylesheet" href="{% static 'plugins/lobibox/lobibox.min.css' %}">**


 <script src="{% static 'plugins/slimScroll/jquery.slimscroll.min.js' %}"></script>

**<script src="{% static 'plugins/moments/moment.min.js' %}"></script>**

It loads some resources while it gives 404 for some other resources that are there and working in my old laptop (the bold ones such as moment.min.js and css files). The configuration is the same since I used virtual environment to start it.

What am I missing please? I am really lost on what it is doing.

Nie Selam
  • 1,343
  • 2
  • 24
  • 56
  • did you check the static folder for the files? do they exist and do they have contents and not being corrupted? try opening them once – Exprator Jun 05 '17 at 10:09
  • Thanks @Exprator : yes, they are there and working fine. Deleted and copied them back again from the old laptop still the same files don't load up. – Nie Selam Jun 05 '17 at 10:11
  • try {% load static %} instead of {% load staticfiles %} and check – Exprator Jun 05 '17 at 10:12
  • I seem to have a bigger problem cos i deleted the entire static folder and still nothing changed even with static instead of staticfiles. Any idea? Cos this is brand new laptop and i just loaded the application now. – Nie Selam Jun 05 '17 at 10:25
  • do you have any other static folder anywhere? inside app? – Exprator Jun 05 '17 at 10:26
  • Try to recheck your configurations, here's a post that could help : https://stackoverflow.com/questions/27755457/django-static-content-not-found?noredirect=1&lq=1 Edited Link – Horai Nuri Jun 05 '17 at 10:29

1 Answers1

0

No question is laughable :)

To begin with, change {% load staticfiles %} to {% load static %}.

Then make sure you've got the correct settings in terms of static files. A good setup would look like this:

STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = '/static/'

If you are running your app without DEBUG=True, then also run python manage.py collectstatic --no-input from your terminal - that should do the trick to serve static assets in prod environment.

Try it and let us know how it went.

Kostas Livieratos
  • 965
  • 14
  • 33
  • Thanks. That didn't really have an effect. I came across STATICFILES_DIRS somewhere here on SO that seemed to work fine for now but I wish your solution worked fine cos STATICFILES_DIRS takes absolute paths making my application non-portable. – Nie Selam Jun 05 '17 at 11:20
  • you can set your `STATICFILES_DIRS` path to `/staticfiles/`, which would make it portable – Kostas Livieratos Jun 05 '17 at 14:04