Static files not found

48 views
Skip to first unread message

Serge Alard

unread,
Feb 3, 2022, 3:22:33 PM2/3/22
to Django users
Hello

I developped a project in Django python that works fine. Thus, I deployed my project. Everything works but the static files are not found by the application.
I give you below the settings and wsgi files.

WSGI
import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Web_bridge.settings')

application = get_wsgi_application()

SETTINGS
import os
from pathlib import Path

os.environ['ENV'] = 'PRODUCTION'

BASE_DIR = Path(__file__).resolve(strict=True).parent.parent

DEBUG = False
SECRET_KEY = 'django-insecure-eqlug^3e20v1c5%mo9*mhhea^vv$!$&hyiz-tr%x&6!@6$+e%7'
ALLOWED_HOSTS = ['*']

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

INSTALLED_APPS = [
'bridge.apps.BridgeConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'Web_bridge.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / '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',
],
},
},
]

WSGI_APPLICATION = 'Web_bridge.wsgi.application'

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql', # on utilise l'adaptateur postgresql
'NAME': 'sudoku_bridge', # le nom de notre base de donnees creee precedemment
'USER': 'sudoku', # attention : remplacez par votre nom d'utilisateur
'PASSWORD': '*',
'HOST': 'postgresql-sudoku.alwaysdata.net',
'PORT': '5432',
'CONN_MAX_AGE': 500,
}
}

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]

LANGUAGE_CODE = 'fr-FR'

TIME_ZONE = 'Europe/Paris'

USE_I18N = True

USE_L10N = True

USE_TZ = False

STATIC_URL = 'static/'

Thank you in advance to help me.

Lakshyaraj Dash X-D 25

unread,
Feb 3, 2022, 3:33:10 PM2/3/22
to django...@googlegroups.com
Please add this line below static_url

STATICFILES_DIRS = [
'static'
]

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1c8bda14-d16f-405f-9c66-29e63275419bn%40googlegroups.com.

Serge Alard

unread,
Feb 3, 2022, 4:59:17 PM2/3/22
to Django users
Thank you for the suggestion but it does not work.
I add 2 things to make easier your helps :
  • the settings and wsgi files are in /www/Web_bridge/ Web_bridge/
  • the static files are in /www/Web_bridge/static/bridge/
Below an example of connexion.html that calls a static file :

{% extends "bridge/sous_base.html" %}

{% block content %}
{% if error_message %}<p class="erreur">{{ error_message }}</p>{% endif %}
<h1>Connexion</h1>
<form action="{% url 'bridge:connexion' %}" method="post">
{% csrf_token %}
<p>
<label>Pseudonyme : </label>
<input type="text" name="pseudo" id="pseudo" value="{{ pseudo }}" required />
<br><br>
<label for="pass">Mot de passe : </label>
<input type="password" name="pass" id="pass" value="{{ mot_de_passe }}"/>
<input type="button" id="visible" value="voir" onclick="Afficher(['pass'])" >
<br><br>
<input type="checkbox" id="oubli" name="oubli" /><label for="oubli">Mot de passe oublié</label>
<br><br>
</p>
<input type="submit" value="Enregistrer">
<input type="button" value="Retour accueil" onclick="location.href='{% url 'bridge:index' %}'">
</form>
{% endblock %}

{% block script %}
{% load static %}
{{ block.super }}
<script src="{% static 'bridge/password.js' %}"></script>
{% endblock %}

Thank you in advance for your suggestions.

Opeyemi Ogunsanya

unread,
Feb 3, 2022, 5:49:33 PM2/3/22
to django...@googlegroups.com
Move the static folder to the Django app folder

Lakshyaraj Dash X-D 25

unread,
Feb 3, 2022, 6:08:05 PM2/3/22
to django...@googlegroups.com
Ok! Actually I had not looked properly to your file. The line that I had given was already in STATIC_ROOT. If you have debug=False, then you can run something like this :
python manage.py runserver --insecure

It will serve your static files while the debug mode is set to false.

Muhammad Muhammad inuwa

unread,
Feb 3, 2022, 7:21:30 PM2/3/22
to django...@googlegroups.com
At the bottom of your code, you need to include the STATICFILES_DIRS = [BASE_DIR/"<your folder directory>"].
This tells django where your static files are

Serge Alard

unread,
Feb 13, 2022, 5:44:54 PM2/13/22
to Django users
To  Ogunsanya Opeyemi : my Django app folder is bridge, thus it's OK
To dashlaksh...@gmail.com : I tried but the static files are not found
To  mminu...@gmail.com :  STATICFILES_DIRS = [BASE_DIR/"<your folder directory>"] is not necessary because it's given already in static_root.
Thank you everybody but it does not work yet.

Serge Alard

Dev femibadmus

unread,
Feb 13, 2022, 9:15:49 PM2/13/22
to django...@googlegroups.com
U need to provide ur static Files dir

Using os.path.join(BASR_DIR, "staticfiles")

Also if u storing ur static file to cloud or any other host present ur STATICFILES_STORAGE="https://domain.com/location/folder"

Feroz Ahmed

unread,
Feb 13, 2022, 10:23:13 PM2/13/22
to django...@googlegroups.com

if

staticfiles folder not exists in project,

 

in that case you have to create folder name as staticfiles in project level

Reply all
Reply to author
Forward
0 new messages