Static files not found
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. -- 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+unsubscr...@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.
Re: Static files not found
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 %}{{ error_message }}{% endif %} Connexion {% csrf_token %} Pseudonyme : Mot de passe : Mot de passe oublié {% endblock %} {% block script %} {% load static %} {{ block.super }} {% endblock %} Thank you in advance for your suggestions. Le jeudi 3 février 2022 à 16:33:10 UTC+1, dashlaksh...@gmail.com a écrit : > Please add this line below static_url > > STATICFILES_DIRS = [ > 'static' > ] > > On Thu, Feb 3, 2022, 20:53 Serge Alard wrote: > >> 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. >> >> -- >> 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 >> >> <https://groups.google.com/d/msgid/django-users/1c8bda14-d16f-405f-9c66-29e63275419bn%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/280871bd-69c4-42a4-b781-578e20c0d7f4n%40googlegroups.com.
Re: Static files not found
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/""] is not necessary because it's given already in static_root. Thank you everybody but it does not work yet. Serge Alard Le jeudi 3 février 2022 à 20:21:30 UTC+1, mminu...@gmail.com a écrit : > At the bottom of your code, you need to include the STATICFILES_DIRS = > [BASE_DIR/""]. > This tells django where your static files are > > On Thu, Feb 3, 2022, 18:49 Opeyemi Ogunsanya > wrote: > >> Move the static folder to the Django app folder >> >> On Thu, Feb 3, 2022, 6:01 PM Serge Alard wrote: >> >>> 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 %}{{ error_message }}{% endif >>> %} >>> Connexion >>> >>> {% csrf_token %} >>> >>> Pseudonyme : >>> >> required /> >>> >>> Mot de passe : >>> >>> >> onclick="Afficher(['pass'])" > >>> >>> Mot >>> de passe oublié >>> >>> >>> >>> >>> >>> {% endblock %} >>> >>> {% block script %} >>> {% load static %} >>> {{ block.super }} >>> >>> {% endblock %} >>> >>> Thank you in advance for your suggestions. >>> >>> Le jeudi 3 février 2022 à 16:33:10 UTC+1, dashlaksh...@gmail.com a >>> écrit : >>> >>>> Please add this line below static_url >>>> >>>> STATICFILES_DIRS = [ >>>> 'static' >>>> ] >>>> >>>> On Thu, Feb 3, 2022, 20:53 Serge Alard wrote: >>>> >>>>> 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.XFrameOptionsMid
To get object id currently modified in django administration
Bonjour Je suis en train de faire des validations personnalisées sur des objets de mon projet dans l'administration de Django. Pour cela j'ai créé un ModelForm, mais je ne sais pas comment accéder à l'objet id en cours de modification dans l'administration de Django. Pourriez-vous m'aider. Merci d'avance. Hello Currently I do customized validations on objects of my project in the Django administration. For that, I created a ModelForm but I do not know how to get the object id currently in modification in Django administration. Could you help me. Thanks in advance. Serge Alard -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aceba62e-5578-435f-9ae3-924f446825b0n%40googlegroups.com.
How to use correctly a FormSet in django administration
Hello I should like to do personalised validation in Django administration but I have always the same error : type object 'MainForm' has no attribute '_meta' To do so, I use the following admin.py (attached file) Thanks in advance to anybody who could me unblocked. Serge Alard -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f66565b5-993e-4d89-b578-fcb1c605a416n%40googlegroups.com. ''' Superuser = admin password = idem à BD ''' from django.contrib import admin from django.forms import BaseModelForm, BaseInlineFormSet from .models import * from django.core.exceptions import ValidationError class MainInlineForm(BaseModelForm): model = Main fields = ('numero', 'pique', 'coeur', 'carreau', 'trefle') class MainInlineFormSet(BaseInlineFormSet): def carte_doublon(self, cartes): if cartes is None: return cartes l = [] for c in cartes: v = valeur_carte(c) l.append((v, c)) l = sorted(l, reverse=True) s = '' for (v, c) in l: s += c sd = '' c0 = None for c in s: if c == c0: sd += c c0 = c return sd def clean(self): if self.errors: return pique = '' for form in self.forms: pique += form.cleaned_data.get('pique') doublons = self.carte_doublon(pique) if len(doublons) > 1: raise ValidationError("'{}' de pique sont en double dans les différentes mains de la donne". format(doublons)) elif len(doublons) == 1: raise ValidationError("'{}' de pique est en double dans les différentes mains de la donne". format(doublons)) class MainInline(admin.StackedInline): model = Main fields = ('numero', 'pique', 'coeur', 'carreau', 'trefle') extra = 2 max_num = 4 form = MainInlineForm formset = MainInlineFormSet class DonneAdmin(admin.ModelAdmin): exclude = ('nb_aleatoire', 'numero') list_filter = ('chapitre',) inlines = (MainInline,) class MainAdmin(admin.ModelAdmin): exclude = ('pointsh',) ordering = ('numero',) def valeur_carte(c): if c == 'A': v = 14 elif c == 'R': v = 13 elif c == 'D': v = 12 elif c == 'V': v = 11 elif c == 'X': v = 10 else: v = ord(c) - 48 return v admin.site.register(Donne, DonneAdmin) admin.site.register(Main, MainAdmin)
How to valid data after the deletion of an inline instance ?
Hello I am using formset to valid inline forms in django administration. To valid my data I am using the method clean() but when I delete an inline object the data are validated before the deletion. How can I do to valid my data after the deletion. Thanks in advance to help me. Serge Alard -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/172a1a3c-dbba-432e-961a-2774e6331f59n%40googlegroups.com.
How to validate data after the deletion of an inline instance ?
Hello I am using a formset to validate inline forms in django administration. To validate my data I am using the method clean() but when I delete an inline object the data are validated before the deletion. How can I validate my data after the deletion ? How can I know that my inline object is deleted in the validation method clean() ? Thanks in advance to help me. Serge Alard P.S. : This message is the same as the one I posted yesterday but I corrected grammatical mistake. -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6d877450-492b-4fb7-bb80-56236dc15986n%40googlegroups.com.
@admin.display(ordering='any_item') does not work !
Hello I have a Sujet that can have sub-Sujet recursively. Here is a test among several ones that does not work : class Sujet(models.Model): objects = None numero = models.PositiveSmallIntegerField() titre = models.CharField(max_length=100) partie = models.ForeignKey('self', models.CASCADE, blank=True, null=True, db_index=False) def __str__(self): if self.partie is None: s = '' else: s = str(self.partie) s2 = '' if len(s) > 0: for i, c in enumerate(s): if c.isdigit(): s2 = s[:(i+2)] elif c == ' ': break s = s2 + str(self.numero) + '. ' s += str(self.titre) return s @admin.register(Sujet) @admin.display(ordering='__str__') class SujetAdmin(admin.ModelAdmin): fields = ('partie', 'numero', 'titre') list_display = ('__str__',) The asked ordering does work. Apparently, it sorts by decreasing order of the Sujet creation. Serge Alard -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ff80ea5a-b04c-4cef-a5c0-47281641e82bn%40googlegroups.com.