Kindly follow this steps:
1. Create a folder under your root folder name it media
2. Your model should look like this:
image = models.ImageField(upload_to ='media/course', default=True)
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'))
3(a). Fix import, by simply add import os in settings.py file
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
On Wednesday, July 7, 2021 at 3:55:58 PM UTC+1 abubak...@gmail.com wrote:
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.
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8738ab83-a998-4b9d-90d2-64839f5b8564n%40googlegroups.com.
No comments:
Post a Comment