Forums

Static issues

I'm trying to call css and image files using the syntax {% load static%} and then

the tag contents: link rel="stylesheet" href="{% static 'css/filename.css' %}" type="text/css"

in settings, I have...

STATIC_URL = '/static/'

STATIC_ROOT = "/home/username.pythonanywhere.com/projname/mysite/static/"

STATICFILES_DIRS = [
     "/home/username.pythonanywhere.com/projname/mysite/static/"
]

Under Web I have specified my folder as /static/ with the corresponding path

I have added this in urls:

from django.conf import settings

from django.conf.urls.static import static

+= static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

It still won't read my css file, and it actually prints "{% load static%}" at the top of the page. I've been reading up, but it's getting more confusing. Do I need to add a new path or URL to my url.py, or is there something else that I am missing?

The documentation says that with DEBUG = TRUE it should automagically seek out my static files. I don't want to keep all of my css and image files in my root folder. That gets messy. Please help!

[formatted by admin]

Are you using username.pythonanywhere.com as a placeholder in the code that you pasted or is it literally copied from your code? Also this += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) looks syntactically wrong (but maybe something was lost during the copying?). Have you checked our help page already? https://help.pythonanywhere.com/pages/DjangoStaticFiles/