[PYTHON] Django1.11.1 Image uploader Easy to stumble

problem

If you implement an image uploader in Django, you can save the image but you can't read it! I thought that I might run into various problems, so I will share it. I don't think there are any mistakes in writing settings.py and models.py, so maybe the big chobo miss points are as follows.

urls.py


from django.conf import settings
from django.conf.urls import url, include
from django.conf.urls.static import static
from django.contrib import admin

urlpatterns = [
    url(r'^myapp/', include('myapp.urls',namespace='myapp')),
    url(r'^admin/', admin.site.urls),
]
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)

I think it can be avoided in general like this. The rest is a template

{% for i in result_list %}
<img src="{{ i.image_url.url }}">
{% endfor %}

It will be OK if you call it like this.

Recommended Posts

Django1.11.1 Image uploader Easy to stumble
Easy to use Flask
unable to import django
How to create an image uploader in Bottle (Python)
Easy to use SQLite3
update django version 1.11.1 to 2.2
Image uploader in Flask
opencv-python Introduction to image processing
Introduction to Python Django (2) Win
Dot according to the image
Easy to read control flow
Shell to create django project
Easy to make with syntax
Easy image classification with TensorFlow
Easy way to rename files
Pass text to Django genericview
Deploy django project to heroku
Easy to use E-Cell 4 Intermediate