Answer the question
In order to leave comments, you need to log in
Can't find the image path?
Ok, that means adding images to Django.
models.py
from django.db import models
# Create your models here.
class Article(models.Model):
class Meta:
db_table = "article"
article_image = models.ImageField(null=True, blank=True, upload_to="Images")
from django.contrib import admin
from article.models import Article
# Register your models here.
class ArticleAdmin(admin.ModelAdmin):
fields = [ 'article_image']
admin.site.register(ArticleAdmin)
STATIC_URL = '/static/'
MEDIA_URL = '/media/'<code lang="html">
</code>
MEDIA_ROOT = os.path.join(BASE_DIR, 'article/media')
{% block articles %}
<img src="{{ article.article_image.url }}">
{% endblock %}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question