Did you create media directory in your base directory? On Thu 27 Aug, 2020, 8:33 PM Tony Hall, <thalldak...@gmail.com> wrote:
> I'm relatively new to programming and I'm having some trouble with the > ImageField in my models.py. > > I keep getting the error in the attachment every time I load the > local:8000. > > My models.py is: > > from django.db import models > > class Pilot(models.Model): > title = models.CharField(max_length=200) > description = models.TextField() > count = models.IntegerField() > writer = models.CharField(max_length=200) > year = models.IntegerField() > script = models.FileField(blank=True, null=True, upload_to="scripts") > poster = models.ImageField(blank=True, null=True, upload_to="posters") > created_at = models.DateTimeField(auto_now_add=True) > updated_at = models.DateTimeField(auto_now=True) > > def __str__(self): > return self.title > > @property > def imageURL(self): > try: > url = self.poster.url > except: > url = '' > print('URL:', url) > return url > > The settings.py : > STATIC_URL = '/static/' > > MEDIA_ROOT = os.path.join(BASE_DIR, 'media') > MEDIA_URL = '/media/' > > STATICFILES_DIR = [ > os.path.join(BASE_DIR, 'static') > ] > > The urls.py: > from django.contrib import admin > from django.urls import path, include > from django.conf import settings > from django.conf.urls.static import static > > urlpatterns = [ > path('admin/', admin.site.urls), > path('', include('script_app.urls')), > ] > > if settings.DEBUG: > urlpatterns += static(settings.STATIC_URL, > document_root=settings.STATIC_ROOT) > urlpatterns += static(settings.MEDIA_URL, > document_root=settings.MEDIA_ROOT) > > > How do I fix this?!!! > > -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/2aae39fa-8fe5-4f83-b139-60918022ae61n%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/2aae39fa-8fe5-4f83-b139-60918022ae61n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAP6mExiz2-3ohsm4izrBUCO8SocmkksocsKe3P_KoTEprLyT6A%40mail.gmail.com.