If
MEDIA_ROOT = '/files/dev/projects/mynewproject/media'
and the URL is
http://localhost:8000/media/adminextra/js/jquery.js
then the local path to the file must be:
/files/dev/projects/mynewproject/media/adminextra/js/jquery.js
whereas you say (in the comment) that your file is located at:
/files/dev/projects/mynewproject/project/concerthall/media/adminextra/js
Of course, it's not found.
This works differently for STATIC paths and URLs because you have the collectstatic
and the STATIC files finder mechanism in between. I recommend placing your resources into the STATIC roots because that is where they belong. MEDIA is not meant for this.
Also, best practice should avoid hard coded absolute file paths in your settings. This won't work in a shared project.
Example setup in <git_root>/mynewproject/settings/base.py
:
BASE_APP_DIR = os.path.dirname(os.path.realpath(project_module.__file__))
PROJECT_DIR = os.path.dirname(BASE_APP_DIR)
# Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static_collected')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
)
STATICFILES_DIRS = (
os.path.join(BASE_APP_DIR, 'static'),
)
with your web resources (JS/CSS/img) residing under <git_root>/mynewproject/static
and lower app directories and being output by collectstatic
into <git_root>/static_collected
. On production you would have NGINX or Apache deliver the files in that latter directory.
Place your file into:
mynewproject/project/concerthall/static/adminextra/js/jquery.js
(I take it, concerthall
is an app with a models.py
file.)
In your admin class that uses it:
class Media:
js = ("adminextra/js/jquery.js",)