2

I am attempting to learn Django development with Bluemix Cloud Foundry and Python 3.5.3.

I have a hello world Website running at this time. But I cannot get static files like CSS to be served.

I think my settings for finding static files are not correct.


My served page is meant to look like:

correct result

What I am getting is:

actual result


I get the correct result locally with Debug = True in settings.py, but not with Debug = False. I cannot get the correct result when pushed to Bluemix, regardless of the Debug setting.

My project folders are set up like this:

Project Folder Structure

the django staticfiles app is in my Installed_Apps variable.

In my settings.py file I have:

...
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# STATICFILES_DIRS = [
#     os.path.join(BASE_DIR, 'bluemixsite/static'),
#     os.path.join(BASE_DIR, 'bluemixapp/static'),
# ]

STATICFILES_DIRS appeared to make no difference with finding static files.

The template page (being loaded) includes the following:

...
{% load static %}

    <link rel="stylesheet" type="text/css" href="{% static 'bluemixapp/stylesheet.css' %}" />
</head>
....

With Debug=False, when inspected in firefox, I can see this message under the style editor both locally and on bluemix:

The requested URL /static/bluemixapp/stylesheet.css was not found on this server.

So either I do not have the files in the correct location, or Django cannot resolve paths to the static files on the server.


I tried the collectstatic command which copied all static files into project_root/static/ folder but this made no difference.

Apparently Bluemix refuses to run linux terminals (they freeze or crash when starting) so I can't do anything at the server end that way.

I cannot load the static files onto a separate server.

Any suggestions would be appreciated.

rask004
  • 552
  • 5
  • 15

2 Answers2

0

Try Loading static from static files instead:

{% load static from staticfiles %}

As mentioned here.

Mamoon Raja
  • 487
  • 3
  • 8
0

You need to run the command python manage.py collectstatic in your src directory in the development framework. (In the folder containing the manage.py file) This will construct a folder containing all your static files in a manner accessible in your production app. For further information you can follow this free tutorial: https://www.coursera.org/lecture/developing-applications-with-sql-databases-and-django/manage-static-files-QGe9i

Yannick Pezeu
  • 530
  • 1
  • 7
  • 12