Home > Blockchain >  Issue with image in django
Issue with image in django

Time:02-12

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)

CodePudding user response:

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
  • Related