Re: [Django] #35290: 500 Server error. Whitenoise Not Working when DEBUG = FALSE - Django - Hosting Static Files

2024-03-12 Thread Django
#35290: 500 Server error. Whitenoise Not Working when DEBUG = FALSE - Django -
Hosting Static Files
-+-
 Reporter:  Shihab Khan  |Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  contrib.staticfiles  |  Version:  4.2
 Severity:  Normal   |   Resolution:
 Keywords:  500 Server error,| Triage Stage:
  Whitenoise,  DEBUG = FALSE |  Unreviewed
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Description changed by Shihab Khan:

Old description:

> I am running a Django website and it's about to go into production. I am
> now at the point where I need to set DEBUG = False in my settings.py
> file. I am getting the typical 500 errors because I have static files
> that are being hosted locally. I am working on getting Whitenoise to work
> to host my static files so I can move on with DEBUG = False. I have
> followed a lot of documentation and a lot of tutorials and think all of
> my configurations are all set but I am still getting the same error. When
> DEBUG = False I am still getting 500 errors on my production pages that
> have static files. Also when I inspect any static files on the page when
> DEBUG = True the URL has not changed at all. I am posting all of my
> configuration below in hopes that there is a simple mistake I made that I
> have been continuously skipped over but Whitenoise doesn't seem to be
> working and there seems to be no different from the way it was before now
> as Whitenoise is "implemented".
>
> I have run python manage.py collect static
>
> I have run pip install whitenoise
>
> I am new to white noise so I am just basing my knowledge on the tutorials
> and documentation I have found.
>

>

> setting.py
> from pathlib import Path
> import os
>
> # Build paths inside the project like this: BASE_DIR / 'subdir'.
> BASE_DIR = Path(__file__).resolve().parent.parent
>
> def load_env():
> env_file = os.path.join(BASE_DIR, '.env')
> if os.path.exists(env_file):
> with open(env_file, 'r') as file:
> for line in file:
> line = line.strip()
> if line and not line.startswith("#"):
> key, value = line.split('=')
> os.environ[key] = value
>
> # Load environment variables from the .env file
> load_env()
>
> # Quick-start development settings - unsuitable for production
> # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
>
> # SECURITY WARNING: keep the secret key used in production secret!
> SECRET_KEY = 'django-
> insecure-x=qe5@^3%@t1fk)pk@uyv&r!z^#9==^*-&aiqfau3@9x@+j%nm'
>
> # SECURITY WARNING: don't run with debug turned on in production!
> DEBUG = True if os.getenv('DEBUG') == 'True' else False
>
> ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS').split(',')
>

> # Application definition
>
> INSTALLED_APPS = [
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 'accounts',
> 'home',
> 'about',
> 'pricing',
> 'blog',
> 'contact',
> 'service',
> 'project',
> 'settings',
> 'legal',
> 'menus',
> 'adminapp',
> 'marketing',
> 'custompage',
> 'ckeditor',
> ]
>
> 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',
> ]
>
> if os.getenv('DEMO_MODE') == 'True':
> MIDDLEWARE.append('core.middleware.middleware.DemoModeMiddleware')
>
> if os.getenv("WHITENOISE_CONFIG") == "True":
> MIDDLEWARE.insert(1, 'whitenoise.middleware.WhiteNoiseMiddleware')
>

> ROOT_URLCONF = 'core.urls'
>
> TEMPLATES = [
> {
> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
> 'DIRS': [os.path.join(BASE_DIR, os.getenv('TEMPLATES_DIRS'))],
> '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',
> 'core.context_processors.website_settings_context',
>

Re: [Django] #35290: 500 Server error. Whitenoise Not Working when DEBUG = FALSE - Django - Hosting Static Files

2024-03-12 Thread Django
#35290: 500 Server error. Whitenoise Not Working when DEBUG = FALSE - Django -
Hosting Static Files
-+-
 Reporter:  Shihab Khan  |Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  contrib.staticfiles  |  Version:  4.2
 Severity:  Normal   |   Resolution:
 Keywords:  500 Server error,| Triage Stage:
  Whitenoise,  DEBUG = FALSE |  Unreviewed
Has patch:  1|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Comment (by Shihab Khan):

 python manage.py collectstaticcommand


 {{{
 (venv) PS C:\Users\intevers\Downloads\django\intevers> python manage.py
 collectstatic

 You have requested to collect static files at the destination
 location as specified in your settings:

 C:\Users\intevers\Downloads\django\intevers\assets

 This will overwrite existing files!
 Are you sure you want to do this?

 Type 'yes' to continue, or 'no' to cancel: yes
 Post-processing 'admin\assets\css\vendors\icon\font-awesome\all.min.css'
 failed!

 Traceback (most recent call last):
   File "C:\Users\intevers\Downloads\django\intevers\manage.py", line 22,
 in 
 main()
   File "C:\Users\intevers\Downloads\django\intevers\manage.py", line 18,
 in main
 execute_from_command_line(sys.argv)
   File "C:\Users\intevers\Downloads\django\intevers\venv\lib\site-
 packages\django\core\management\__init__.py", line 442, in
 execute_from_command_line
 utility.execute()
   File "C:\Users\intevers\Downloads\django\intevers\venv\lib\site-
 packages\django\core\management\__init__.py", line 436, in execute
 self.fetch_command(subcommand).run_from_argv(self.argv)
   File "C:\Users\intevers\Downloads\django\intevers\venv\lib\site-
 packages\django\core\management\base.py", line 412, in run_from_argv
 self.execute(*args, **cmd_options)
   File "C:\Users\intevers\Downloads\django\intevers\venv\lib\site-
 packages\django\core\management\base.py", line 458, in execute
 output = self.handle(*args, **options)
   File "C:\Users\intevers\Downloads\django\intevers\venv\lib\site-
 packages\django\contrib\staticfiles\management\commands\collectstatic.py",
 line 209, in hand
 le
 collected = self.collect()
   File "C:\Users\intevers\Downloads\django\intevers\venv\lib\site-
 packages\django\contrib\staticfiles\management\commands\collectstatic.py",
 line 154, in coll
 ect
 raise processed
 whitenoise.storage.MissingFileError: The file
 'admin/assets/css/vendors/icon/webfonts/fa-brands-400.woff2' could not be
 found with .

 The CSS file 'admin\assets\css\vendors\icon\font-awesome\all.min.css'
 references a file which could not be found:
   admin/assets/css/vendors/icon/webfonts/fa-brands-400.woff2

 Please check the URL references in this CSS file, particularly any
 relative paths which might be pointing to the wrong location.
 }}}
-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e31fc94f1-33aa3843-b392-423f-836a-d390c8cc06e5-00%40eu-central-1.amazonses.com.


[Django] #35290: 500 Server error. Whitenoise Not Working when DEBUG = FALSE - Django - Hosting Static Files

2024-03-12 Thread Django
#35290: 500 Server error. Whitenoise Not Working when DEBUG = FALSE - Django -
Hosting Static Files
-+-
   Reporter: |  Owner:  nobody
  cyberindav |
   Type:  Bug| Status:  new
  Component: |Version:  4.2
  contrib.staticfiles|   Keywords:  500 Server error,
   Severity:  Normal |  Whitenoise,  DEBUG = FALSE
   Triage Stage: |  Has patch:  1
  Unreviewed |
Needs documentation:  0  |Needs tests:  0
Patch needs improvement:  0  |  Easy pickings:  0
  UI/UX:  0  |
-+-
 I am running a Django website and it's about to go into production. I am
 now at the point where I need to set DEBUG = False in my settings.py file.
 I am getting the typical 500 errors because I have static files that are
 being hosted locally. I am working on getting Whitenoise to work to host
 my static files so I can move on with DEBUG = False. I have followed a lot
 of documentation and a lot of tutorials and think all of my configurations
 are all set but I am still getting the same error. When DEBUG = False I am
 still getting 500 errors on my production pages that have static files.
 Also when I inspect any static files on the page when DEBUG = True the URL
 has not changed at all. I am posting all of my configuration below in
 hopes that there is a simple mistake I made that I have been continuously
 skipped over but Whitenoise doesn't seem to be working and there seems to
 be no different from the way it was before now as Whitenoise is
 "implemented".

 I have run python manage.py collect static

 I have run pip install whitenoise

 I am new to white noise so I am just basing my knowledge on the tutorials
 and documentation I have found.




 setting.py
 from pathlib import Path
 import os

 # Build paths inside the project like this: BASE_DIR / 'subdir'.
 BASE_DIR = Path(__file__).resolve().parent.parent

 def load_env():
 env_file = os.path.join(BASE_DIR, '.env')
 if os.path.exists(env_file):
 with open(env_file, 'r') as file:
 for line in file:
 line = line.strip()
 if line and not line.startswith("#"):
 key, value = line.split('=')
 os.environ[key] = value

 # Load environment variables from the .env file
 load_env()

 # Quick-start development settings - unsuitable for production
 # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

 # SECURITY WARNING: keep the secret key used in production secret!
 SECRET_KEY = 'django-
 insecure-x=qe5@^3%@t1fk)pk@uyv&r!z^#9==^*-&aiqfau3@9x@+j%nm'

 # SECURITY WARNING: don't run with debug turned on in production!
 DEBUG = True if os.getenv('DEBUG') == 'True' else False

 ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS').split(',')


 # Application definition

 INSTALLED_APPS = [
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'accounts',
 'home',
 'about',
 'pricing',
 'blog',
 'contact',
 'service',
 'project',
 'settings',
 'legal',
 'menus',
 'adminapp',
 'marketing',
 'custompage',
 'ckeditor',
 ]

 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',
 ]

 if os.getenv('DEMO_MODE') == 'True':
 MIDDLEWARE.append('core.middleware.middleware.DemoModeMiddleware')

 if os.getenv("WHITENOISE_CONFIG") == "True":
 MIDDLEWARE.insert(1, 'whitenoise.middleware.WhiteNoiseMiddleware')


 ROOT_URLCONF = 'core.urls'

 TEMPLATES = [
 {
 'BACKEND': 'django.template.backends.django.DjangoTemplates',
 'DIRS': [os.path.join(BASE_DIR, os.getenv('TEMPLATES_DIRS'))],
 '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',
 'core.context_processors.website_settings_context',
 'core.context_processors.seo_settings_context',
 'core.context_processors.header_footer_context',
 'core.