AttributeError: 'settings' object has no attribute
Question:
Examined the documentation of django and this post Django MEDIA_URL and MEDIA_ROOT but, I’m still having issues, at first It was a SQlight issue so, I updated to latest Django from Django 2 now I’m getting:
AttributeError: ‘Settings’ object has no attribute ‘MEDIA_Root’
Settings.py
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
urls.py
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = patterns('',
path('admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT),
Also tried this:
urlpatterns = [
path('admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT),
Answers:
I guess you actually imported wrong settings
. Re-check your actually code. Instead of importing this (upper-case):
from django.conf import Settings
you should import this (lower-case)
from django.conf import settings
Also, as was pointed in comments, this is an error (or you incorrectly pasted the code here):
'MEDIA_Root'STATIC_URL = '/static/'
Removed the comma at the end:
Bad Code:
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT),
Good Code:
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
For me, I did a mistake on the name part.
I was getting
Settings' object has no attribute 'STATIC'
My code was :
static(settings.STATIC_URL, document_root=settings.STATIC.ROOT)
My Code should have been :
static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Examined the documentation of django and this post Django MEDIA_URL and MEDIA_ROOT but, I’m still having issues, at first It was a SQlight issue so, I updated to latest Django from Django 2 now I’m getting:
AttributeError: ‘Settings’ object has no attribute ‘MEDIA_Root’
Settings.py
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
urls.py
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = patterns('',
path('admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT),
Also tried this:
urlpatterns = [
path('admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT),
I guess you actually imported wrong settings
. Re-check your actually code. Instead of importing this (upper-case):
from django.conf import Settings
you should import this (lower-case)
from django.conf import settings
Also, as was pointed in comments, this is an error (or you incorrectly pasted the code here):
'MEDIA_Root'STATIC_URL = '/static/'
Removed the comma at the end:
Bad Code:
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT),
Good Code:
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
For me, I did a mistake on the name part.
I was getting
Settings' object has no attribute 'STATIC'
My code was :
static(settings.STATIC_URL, document_root=settings.STATIC.ROOT)
My Code should have been :
static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)