Re: i have a picture field in my model that was not stored properly in django database and i can't retrive that picture

34 views
Skip to first unread message
Message has been deleted

DJANGO DEVELOPER

unread,
Jul 7, 2021, 10:55:58 AM7/7/21
to Django users
you're doing well but it is not the right way o ask the question. you need to describe all of your problem and what you have done to resolve it, then may be someone will be able to help you.

On Wed, Jul 7, 2021 at 7:07 PM Hugh Frost <mohansar...@gmail.com> wrote:
please check below view Function

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8d5c1a31-8781-4eec-8840-bc6b58969c97n%40googlegroups.com.

Lalit Suthar

unread,
Jul 7, 2021, 12:52:02 PM7/7/21
to django...@googlegroups.com

dapsyn

unread,
Jul 7, 2021, 2:16:34 PM7/7/21
to Django users

Try check your model

dapsyn

unread,
Jul 7, 2021, 2:16:52 PM7/7/21
to Django users
Kindly follow this steps:
1.  Create a folder under your root folder name it media 

media.PNG


2. Your model should look like this:
image   = models.ImageField(upload_to ='media/course', default=True)
model.PNG

3. Go to settings, add the followings;
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS= [
    os.path.join(BASE_DIR,'static')
    ]
MEDIA_URL = '/media/'
MEDIA_ROOT = (BASE_DIR.joinpath(BASE_DIR, 'media'))

setting.PNG



3(a). Fix import, by simply add import os in settings.py file
imprt os.PNG


4. Go to your root, urls.py,
Fix import
paste the following;

from django.conf import settings
from django.conf.urls.static import static


paste the following beneath the urlpatterns as shown in the img;
if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns +=  static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

e.g url_set.PNG

Reply all
Reply to author
Forward
0 new messages