4

i am building real estate web app. My static files are not getting loaded.

I have done all the possible settings to laod my static files in my app but it doesn't work. Below is my code, could any one help me to get rid of this.

{% load static %}
<!DOCTYPE html>
<head>
<title>Marwat Real Estate</title>
<link rel="stylesheet" href="{% static 'css/all.css' %}">
<!-- Bootstrap -->
<link rel="stylesheet" href="{% static 'css/bootstrap.css' %}">
<!-- Custom -->
<link rel="stylesheet" href="{% static 'css/style.css' %}">
<!-- light box -->
<link rel="stylesheet" href="{% static 'css/lightbox.min.css' %}">



STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIR = [
os.path.join(BASE_DIR, 'btre/static')
]
Noman marwat
  • 353
  • 1
  • 18
  • 1
    make sure your `urls.py` has `urlpatterns = [ # ... the rest of your URLconf goes here ... ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)` – Hari Apr 07 '19 at 07:16
  • I paste this code in my urls.py but not working.. how to config this settings? – Noman marwat Apr 07 '19 at 16:48

1 Answers1

1

Follow this steps:

  1. Make a folder named static in the app(where you are working in)
  2. Make the style.css inside the static folder
  3. Make a folder named templates in the project folder.
  4. Add a html file inside the templates folder.
  5. Register the templates folder in the settings.py. eg:

      TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            'templates'
            ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
    ]
    
  6. Add the static files inside the html file as given below: eg:

{% load staticfiles %}
<link rel="stylesheet" href="{% static "style.css" %}" /> 

Happy Djangoing... :)

Joju
  • 26
  • 3