in settings.py
MEDIA_ROOT = os.path.join(BASE_DIR,'pictures')
MEDIA_URL = '/pictures/'
in models.py
class Campaign(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
# this is many to one relationship, on_deleting user, profile will also be deleted
campaign_title = models.CharField(max_length=200, blank=True)
campaign_image = models.ImageField(default="default_campaign.png",upload_to="campaign_pictures")
in views.py
def landing_page(request):
campaigns = Campaign.objects.all().order_by('-id')
print(campaigns)
return render(request, 'core/landing_page.html',{'campaigns':campaigns})
in landing_page.html
{% for campaign in campaigns %}
<img src="{{campaign.campaign_image.url}}">
{% endfor %}
issue
I think you missed in urls.py file
from django.conf import settings
from django.conf.urls import url
from django.conf.urls.static import static
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
Also correct it with
campaign_image = models.ImageField(default="default_campaign.png",upload_to="campaign_pictures/")