-2

I have problem with image in django. I get 404.

Settings.py

MEDIA_ROOT = 'static/image/'
MEDIA_URL = 'image/'
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
    ]

Models.py

    img = models.ImageField(upload_to = '', verbose_name= 'Картинка',null=True )

(P.S I tried everything,but it isnt working)

MihailCapone
  • 57
  • 1
  • 5
  • You haven't tried everything. For instance, you haven't tried explaining what is the problem. – NixonSparrow Feb 10 '22 at 20:39
  • 1
    You have a problem with image on template.html? – Luiz Feb 10 '22 at 20:56
  • @NixonSparrow, sorry, I was busy and I think, I didn't explain sone details. I tried to do almost everything. I got 404,when I tried to click on the link in admin control panel and I got 404 – MihailCapone Feb 11 '22 at 07:37

1 Answers1

2

Have you got your answer or not if not try this

Add this in your settings.py file

MEDIA_ROOT = os.path.join(BASE_DIR, 'media') #new
MEDIA_URL = '/media/' #new

After Add in your main urls.py file add these config

from django.conf import settings     #new
from django.conf.urls.static import static  #new
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('App.urls'))
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)      #media
Tanveer Ahmad
  • 706
  • 4
  • 12