Reputation: 3663
In settings.py
, part of my code sets the static url.
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = '/static/'
My static files and folders are at /home/myLinuxUsername/myApp/static/interactive-preview-dependencies
. That has the folders containing CSS, JS and images. It has the folders images
, scripts
and stylesheets
.
My urls.py
's urlpatterns
is like this:
urlpatterns = [
# .. SOME CODE HERE ..
url(r'^interactive/$', interactive),
]
My views.py
is like this:
def interactive(request):
t= get_template('interactive/index.html')
return HttpResponse(t.render())
And here's an example of how I try to load CSS on interactive/index.html
(updated):
<link rel="stylesheet" href=static 'interactive-preview-dependencies/styles/main.css' %}">
When I run python manage.py runserver
and go to localhost:8000/interactive
, the terminal gives me this error: "GET /static/interactive-preview-dependencies/styles/main.css HTTP/1.1" 404 1757
How do I fix this so Django finds and loads the CSS?
Upvotes: 1
Views: 242
Reputation: 3535
If I understand correctly, your app is called myApp
and interactive-preview-dependencies
is just a subfolder inside /home/myLinuxUsername/myApp/static/
. According to Managing static files. You should reference it as
... href="{% static "myApp/interactive-preview-dependencies/styles/main.css" %}"
Upvotes: 1