1

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),
Dr Goat
  • 33
  • 1
  • 1
  • 10

3 Answers3

1

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/'
Charnel
  • 4,222
  • 2
  • 16
  • 28
  • I put Settings.py to make sure the code was categorized and easier to read. It has no function then it being a TAB on Tree view in the ATOM editor. settings is all lower case. – Dr Goat Feb 03 '20 at 17:46
  • @DrGoat perhaps [this](https://stackoverflow.com/a/12839276/4996863) answer will spear light on your problem? – Charnel Feb 03 '20 at 17:50
  • The 8 year old post you linked got me into hair pulling mode. I looked for 2/3hrs and got my self into a (urls.E004)Your URL pattern issue. I reverted to the past code and restarted the server but, nothing is working. its stuck in that ERROR – Dr Goat Feb 03 '20 at 19:50
  • Ok, let go harder way - post an exception trace. – Charnel Feb 03 '20 at 19:57
  • I figured out what happened with the urls.0004 Error I put a Comma next to media example> ('media'), but, before it was ('media') I reverted this change but,the error is not changing. – Dr Goat Feb 03 '20 at 21:12
  • 1
    Thanks for the Help Charnel. Can you please up mark my answer. – Dr Goat Feb 03 '20 at 21:55
1

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)
David Wolf
  • 1,400
  • 1
  • 9
  • 18
Dr Goat
  • 33
  • 1
  • 1
  • 10
0

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)
shotu
  • 46
  • 8