41
What is the production.py
file? How do you import your settings?
Depending on how you got this error (serving django through a wsgi server or on the command line), check for manage.py
or wsgi.py
to see what is the name of the default settings file.
If you want to manuallly set the settings to use, use something like this:
./manage.py --settings=production
Where production
is any python module.
Moreover, your settings file should not import anything django related. If you want to split your settings for different environments, use something like this.
A file settings/base.py
# All settings common to all environments
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
Files like settings/local.py
, settings/production.py
β¦
# Production settings
from settings.base import *
DEBUG = False
DATABASES = β¦
41
If you are using Django 2.2
or greater, your settings file already has a line similar to this:
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Therefore you can easily set static like so:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
- [Django]-Converting timezone-aware datetime to local time in Python
- [Django]-Django: Grab a set of objects from ID list (and sort by timestamp)
- [Django]-Distributing Django projects with unique SECRET_KEYs
3
Set the STATIC_ROOT
setting to the directory from which youβd like to serve static files, for example:
STATIC_ROOT = "/var/www/example.com/static/"
The settings you are using are for development. Check the Django docs for more information here
- [Django]-Django Rest framework, how to include '__all__' fields and a related field in ModelSerializer ?
- [Django]-Django β Overriding the Model.create() method?
- [Django]-How to automate createsuperuser on django?
2
Django settings for static assets can be a bit difficult to configure and debug. However, if you just add the following settings to your settings.py, everything should work exactly as expected:
goto "settings.py" add following code
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
See a full version of our example settings.py on GitHub.
now create static folder in root directory, and a random file inside
it.
Django wonβt automatically create the target directory (STATIC_ROOT) that collectstatic uses, if it isnβt available. You may need to create this directory in your codebase, so it will be available when collectstatic is run. Git does not support empty file directories, so you will have to create a file inside that directory as well.
for more refer: https://devcenter.heroku.com/articles/django-assets
- [Django]-Django: Catching Integrity Error and showing a customized message using template
- [Django]-What is the difference between null=True and blank=True in Django?
- [Django]-Django accessing ManyToMany fields from post_save signal
0
This is the most basic and easy solution, i faced the same error while installing datta admin
.
This solved my problem. Add this code in your settings.py
file in your project core directory.
STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / STATIC_URL
- [Django]-Django: using blocks in included templates
- [Django]-How to display all model fields with ModelSerializer?
- [Django]-Use Django ORM as standalone