Answer the question
In order to leave comments, you need to log in
ImageField django how to display an image?
How to use imagefield? Can someone write on the shelves? There are only old answers in Google :(
and it is desirable to create an example in which, through the admin panel, upload a picture to the page. i.e., in the admin panel, I selected a picture, and it was uploaded where you indicated.
Where to create media folders? In the same folder as manage. py? or before the manage.py folder, or in the application folder itself?))
settings
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = '/media/'
MEDIA_ROOT = os. path.join(BASE_DIR, 'media')
url
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.
models
image = models.ImageField(upload_to='images/', null=True, blank=True)
html
{% if article.image %}
--- < img src="{{article.image}}" > -- -
{% else %}
No image
{% endif %}
ps I don't upload full html, the cycle is working, everything works, the problem is only with displaying images... It
gives the following error OperationalError at /
no such column: testsite_article.image
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