logo
down
shadow

Django 2.2 staticfiles do not work in development


Django 2.2 staticfiles do not work in development

By : LorPag
Date : November 28 2020, 12:01 PM
I hope this helps you . I'm making a new django app where a user can upload images and then they can be displayed on a page. I've read the django docs 10000 times through and I still don't understand why my images aren't loading (DEBUG = True) ,
Serving files uploaded by a user during development¶
code :
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)


Share : facebook icon twitter icon
How to configure django-compressor and django-staticfiles with Amazon's S3?

How to configure django-compressor and django-staticfiles with Amazon's S3?


By : Vinay Chaurasia
Date : March 29 2020, 07:55 AM
it fixes the issue Your settings look correct. You should keep both STATICFILES_STORAGE and COMPRESS_STORAGE set to storage.CachedS3BotoStorage though and not switch back to storages.backends.s3boto.S3BotoStorage.
According to this django-compressor issue, the problem is with the way django-staticfiles saves during the collectstatic process (using shutil.copy2). This issue has been corrected in the newer version of django-staticfiles, which can be used instead of the one that ships with Django 1.3.
code :
pip install django-staticfiles==dev
STATICFILES_FINDERS = (
    #"django.contrib.staticfiles.finders.FileSystemFinder",
    #"django.contrib.staticfiles.finders.AppDirectoriesFinder",
    "staticfiles.finders.FileSystemFinder",
    "staticfiles.finders.AppDirectoriesFinder",
    "compressor.finders.CompressorFinder",
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    #'django.contrib.staticfiles',
    'staticfiles',
    #...
)
How to serve admin static files with django.contrib.staticfiles in Django 1.4 (using one Apache server)?

How to serve admin static files with django.contrib.staticfiles in Django 1.4 (using one Apache server)?


By : Augustus
Date : March 29 2020, 07:55 AM
will help you Daniel Roseman for the explanation and giving me the chance to learn it on my own (and now I won't forget!) :-).
Initially I was really confused and I didn't know you had to first collect the static files, then tell Apache to serve it. I thought simply using STATICFILES_DIRS and including the static app in settings.py was good enough.
code :
STATIC_ROOT = '/var/www/localhost/htdocs/mysite/static/'
STATIC_URL = '/static/' # default
Alias /static/ /var/www/localhost/htdocs/mysite/static/
#In the form of...
#Alias STATIC_URL STATIC_ROOT

<Directory /var/www/localhost/htdocs/mysite/static>
    Order deny,allow
    Allow from all
</Directory>

WSGIScriptAlias / /var/www/localhost/htdocs/mysite/mysite/wsgi.py
WSGIPythonPath /var/www/localhost/htdocs/mysite

<Directory /var/www/localhost/htdocs/mysite/mysite>
    <Files wsgi.py>
        Order deny,allow
        Allow from all
    </Files>
</Directory>
How can I set up Debian x86_64 so a Django project sees django.contrib.staticfiles?

How can I set up Debian x86_64 so a Django project sees django.contrib.staticfiles?


By : Tom
Date : March 29 2020, 07:55 AM
Hope this helps What I saw was irritation at a manage.py that was out of sync with the newer version of python the system was running.
The new, working manage.py, with old one commented out, is:
code :
#!/usr/bin/env python
import os, sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pragmatometer.settings")
    from django.core.management import execute_from_command_line
    execute_from_command_line(sys.argv)
##!/usr/bin/env python
#from django.core.management import execute_manager
#import imp
#try:
#    imp.find_module('settings') # Assumed to be in the same directory.
#except ImportError:
#    import sys
#    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
#    sys.exit(1)
#
#import settings
#
#if __name__ == "__main__":
#    execute_manager(settings)
How to use different staticfiles location based on if it is development or production server

How to use different staticfiles location based on if it is development or production server


By : Andrew Patterson
Date : March 29 2020, 07:55 AM
I wish this help you You're on the right track with your if statement, however, your argv approach is very fragile. For example, you could run the same script with python manage.py runserver or manage.py runserver, changing the argument order and breaking your logic.
Instead, there are two more sturdy approaches you can use; The easiest it to use the DEBUG setting to determine if you're in development or production.
code :
if DEBUG:
    # assume we're local
else:
    # otherwise assume we're in production
import os

# get environment variable ENV from the system
# default to prod if it doesn't exist
ENV = os.getenv('ENV', 'prod')

if ENV == 'local':
    # use local settings
elif ENV == 'stage':
    # use staging settings
else:
    # assume we're in prod
ENV = os.getenv('ENV', 'prod')

SOME_SETTING = 'no.png'

if ENV == 'local':
    import settings_local # could override SOME_SETTING
else:
    import settings_prod # could also override SOME_SETTING
How to fix [Errno 20] Not a directory: '/app/myProjectManager/settings.py/staticfiles/staticfiles.json' Django

How to fix [Errno 20] Not a directory: '/app/myProjectManager/settings.py/staticfiles/staticfiles.json' Django


By : user3618114
Date : March 29 2020, 07:55 AM
like below fixes the issue
[Errno 20] Not a directory: '/app/myProjectManager/settings.py/staticfiles/staticfiles.json'
code :
PROJECT_ROOT = os.path.join(os.path.abspath(__file__))
# PROJECT_ROOT: '/app/myProjectManager/settings.py/'
# STATIC_ROOT: '/app/myProjectManager/settings.py/staticfiles/'
# which is incorrect
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# PROJECT_ROOT: '/app/'
# STATIC_ROOT: '/app/staticfiles/'
Related Posts Related Posts :
  • Tuning the hyperparameter with gridsearch results in overfitting
  • some coordinates that I extracted from geocoder in Python are not saving in the variable I created
  • 7C in cs circles- python Im not sure what is wrong with this yet
  • How to fix 'AttributeError: 'list' object has no attribute 'shape'' error in python with Tensorflow / Keras when loading
  • python - thread`s target is a method of an object
  • Retrieve Variable From Class
  • What is the reason for matplotlib for printing labels multiple times?
  • Why would people use ThreadPoolExecutor instead of direct function call?
  • When clear_widgets is called, it doesnt remove screens in ScreenManager
  • Python can't import function
  • Pieces doesn't stack after one loop on my connect4
  • How to change font size of all .docx document with python-docx
  • How to store a word with # in .cfg file
  • How to append dictionaries to a dictionary?
  • How can I scrape text within paragraph tag with some other tags then within the paragraph text?
  • Custom entity ruler with SpaCy did not return a match
  • Logging with two handlers - one to file and one to stderr
  • How to do pivot_table in dask with aggfunc 'min'?
  • This for loop displays only the last entry of the student record
  • How to split a string by a specific pattern in number of characters?
  • Python 3: how to scrape research results from a website using CSFR?
  • Setting the scoring parameter of RandomizedSeachCV to r2
  • How to send alert or message from view.py to template?
  • How to add qml ScatterSeries to existing qml defined ChartView?
  • Django + tox: Apps aren't loaded yet
  • My css and images arent showing in django
  • Probability mass function sum 2 dice roll?
  • Cannot call ubuntu 'ulimit' from python subprocess without using shell option
  • Dataframe Timestamp Filter for new/repeating value
  • Problem with clicking select2 dropdownlist in selenium
  • pandas dataframe masks to write values into new column
  • How to click on item in navigation bar on top of page using selenium python?
  • Add multiple EntityRuler with spaCy (ValueError: 'entity_ruler' already exists in pipeline)
  • error when replacing missing ')' using negative look ahead regex in python
  • Is there a way to remove specific strings from indexes using a for loop?
  • select multiple tags by position in beautifulSoup
  • pytest: getting AttributeError: 'CaptureFixture' object has no attribute 'readouterror' capturing stdout
  • Shipping PyGObject/GTK+ app on Windows with MingW
  • Python script to deduplicate lines in multiple files
  • How to prevent window and widgets in a pyqt5 application from changing size when the visibility of one widget is altered
  • How to draw stacked bar plot from df.groupby('feature')['label'].value_counts()
  • Python subprocess doesn't work without sleep
  • How can I adjust 'the time' in python with module Re
  • Join original np array with resulting np array in a form of dictionary? multidimensional array? etc?
  • Forcing labels on histograms in each individual graph in a figure
  • For an infinite dataset, is the data used in each epoch the same?
  • Is there a more efficent way to extend a string?
  • Is it possible to do this loop in a one-liner?
  • invalid literal for int() with base 10: - django
  • Why does my code print a value that I have not assigned as yet?
  • the collatz func in automate boring stuff with python
  • How to find all possible combinations of parameters and funtions
  • about backpropagation deep neural network in tensorflow
  • Sort strings in pandas
  • How do access my flask app hosted in docker?
  • Replace the sentence include some text with Python regex
  • Counting the most common element in a 2D List in Python
  • logout a user from the system using a function in python
  • mp4 metadata not found but exists
  • Django: QuerySet with ExpressionWrapper
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org