image didn't upload

28 views
Skip to first unread message

omar ahmed

unread,
Mar 14, 2019, 8:12:53 AM3/14/19
to Django users
this is my model
class LeagueNews(models.Model):
...
news_image = models.ImageField(upload_to='core/media/core',max_length=255, null=True,blank=True)


and this is my template


{% block content %}

<h1 style="color:deeppink;">{{ article.news_title }}</h1>

<h6>{{ article.publication_date }}</h6>

<p>{{ article.news_text }}</p>

<img src="{{ article.news_image }}" height="200"/>

{% endblock %}
the view

def newsdetail(request, news_id):
article = get_object_or_404(LeagueNews,pk=news_id)
return render(request, 'core/newsdetail.html',{'article':article})

Chetan Ganji

unread,
Mar 14, 2019, 8:36:35 AM3/14/19
to django...@googlegroups.com
Did you setup MEDIA-ROOT location in your settings.py
For reference - 

Regards,
Chetan Ganji
+91-900-483-4183


I’m protected online with Avast Free Antivirus. Get it here — it’s free forever.

--
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 post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1d4123b8-c5bc-4bed-8888-51bb142f21b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I’m protected online with Avast Free Antivirus. Get it here — it’s free forever.

omar ahmed

unread,
Mar 14, 2019, 11:46:24 AM3/14/19
to Django users
thanks but it doesn't work
MEDIA_URL = '/media/'
MEDIA_ROOT = 'media'

Chetan Ganji

unread,
Mar 14, 2019, 11:51:25 AM3/14/19
to django...@googlegroups.com
See this works or not.


# Static files (CSS, JavaScript, Images)

STATIC_URL = '/static/'
MEDIA_URL = '/media/'

STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]

MEDIAFILES_DIRS = [
os.path.join(BASE_DIR, 'media'),
]

STATIC_ROOT = os.path.join(BASE_DIR, 'static-root')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media-root')




Regards,
Chetan Ganji
+91-900-483-4183


I’m protected online with Avast Free Antivirus. Get it here — it’s free forever.

AbsolutEdge findout

unread,
Mar 14, 2019, 12:26:26 PM3/14/19
to Django users
Hello omar,

I don't see that you're uploading the picture anywhere, you haven't used a form to upload the image, your template is just trying to display the image, where are the views? and where's the form by which you uploaded the image?

Post all of these please.

Thanks,
Majid

omar ahmed

unread,
Mar 14, 2019, 1:32:18 PM3/14/19
to Django users
i want to post image in news page
Reply all
Reply to author
Forward
0 new messages