57๐
I added the same line in my urls.py and got the same error as you.
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
The documentation here says to use settings.STATIC_URL
and settings.STATIC_ROOT
I changed it to the documentation version
urlpatterns = patterns('',
....urls......
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
and the error went away!
I checked my settings file and made sure settings.MEDIA_URL
and settings.MEDIA_ROOT
were both defined correctly. Later I adjusted urls.py back to using settings.MEDIA_URL
and settings.MEDIA_ROOT
. Everything worked as expected.
These are the relevant parts of my settings.py file:
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
REPOSITORY_ROOT = os.path.dirname(BASE_DIR)
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(REPOSITORY_ROOT, 'static/')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(REPOSITORY_ROOT, 'media/')
I think MEDIA_URL
was set incorrectly
5๐
You have too check both of the MEDIA_URL and MEDIA_ROOT as well as for static files STATIC_ROOT STATIC_URL are defined correctly.
Check correct spelling also ๐
If one of them is miss configured those will cause this error.
- [Django]-Deploying Google Analytics With Django
- [Django]-Can't run the server on Django (connection refused)
- [Django]-Django Rest Framework โ Authentication credentials were not provided
4๐
To resolve the problem, the following statements must be added to the settings.py file:
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
- [Django]-How do I package a python application to make it pip-installable?
- [Django]-What is an efficient way of inserting thousands of records into an SQLite table using Django?
- [Django]-How to use "AND" in a Django filter?
3๐
Make sure that settings.py has:
# Media
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
Then in the urls.py, try this
urlpatterns[
...
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
- [Django]-How to access custom HTTP request headers on Django Rest Framework?
- [Django]-How can my django model DateField add 30 days to the provided value?
- [Django]-How do you change the collation type for a MySQL column?
2๐
Just in case you have this issue, ensure you have both MEDIA_URL AND MEDIA_ROOT set.
I was receiving the error
ImproperlyConfigured at / Empty static prefix not permitted
when I only had MEDIA_ROOT set in django 1.11
Alternatively, django project wiki says that it cannot refer to a URL in debug mode:
https://docs.djangoproject.com/en/1.11/howto/static-files/#serving-files-uploaded-by-a-user-during-development
- [Django]-How to translate docker-compose.yml to Dockerrun.aws.json for Django
- [Django]-Django Installed Apps Location
- [Django]-Adding a APIView to Django REST Framework Browsable API
2๐
I am following Django 2.2 & Python | The Ultimate Web Development Bootcamp my issue was that I have forgot to declare these to portfolio-project/portfolio/settings.py/ to the bottom area:
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/Media/'
- [Django]-Timezone.now() vs datetime.datetime.now()
- [Django]-"_set" in a queryset object in Django
- [Django]-Django โ two views, one page
1๐
I had recently got the same error when working with Django 2.1 The problem was I did not specify explicitly MEDIA_URL = '/media/'
in the project settings file. Once I declared the same the error went away.
- [Django]-How to get the current URL within a Django template?
- [Django]-How to get primary keys of objects created using django bulk_create
- [Django]-Django 1.5b1: executing django-admin.py causes "No module named settings" error
0๐
To fix this error, I had to put STATIC_ROOT
and STATIC_URL
above the STATICFILES_DIRS
declaration.
- [Django]-Disabled field is not passed through โ workaround needed
- [Django]-Django admin DoesNotExist at /admin/
- [Django]-How to test "render to template" functions in django? (TDD)
-1๐
Fix this error by adding this line in urls.py
urlpatterns = [
....
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
- [Django]-Django admin and MongoDB, possible at all?
- [Django]-Django: Validate file type of uploaded file
- [Django]-Django Test Client Method Override Header