1

I have created CSS files in a folder static and currently I'm getting this error 404 when its trying to load the page and no css is being recognised.

my folders are

DEMOPROJECT
    -DEMOAPP
     --migrations
     --templates
        ---DEMOAPP
               -----homepage.html
            ----base.html
    -DEMOPROJECT
         --static
             ---css
                ----NavMENU.css
         --settings.py
         --urls.py

My terminal is this

(venv) C:\Users\jferguson\PycharmProjects\WebP1\DEMOPROJECT> 

I have tried different settings that every other person has asked. None seem to be working.

THIS is in the urls.py file for static folder.

urlpatterns = [
                  re_path(r'^admin/', include(wagtailadmin_urls)),
                  re_path(r'^documents/', include(wagtaildocs_urls)),
                  re_path(r'', include(wagtail_urls)),
              ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

This is in settings

STATIC_URL = '/static/'

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

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

EDIT My homepage_html has this at the top.

{% extends "../base.html" %}
{% load static %}
{% load wagtailcore_tags wagtailimages_tags %}
{% block body_class %}home{% endblock %}

{% block content %}

3 Answers 3

1

Execute collectstatic command as follow

python manage.py collectstatic

In your settings.py file add:

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

In your case :

STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'DEMOPROJECT/static') ]
Sign up to request clarification or add additional context in comments.

4 Comments

@Joeld does your Html template loaded?
then in template have you loaded static files as like {% load static%}?
I have indeed. The problem doesn't seem to be that though. Its more just the locating of the static files.
You have do something like: STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'DEMOPROJECT/static') ] Hope this will work
0

try this python manage.py collectstatic and restart your server. Hope so this will help you.

Comments

0

Thanks Meha Parekh for the answer!

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

This works ^ instead of the following code in settings.py

STATIC_URL = '/static/'

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.