Excuse me, but my Django doesn't display uploaded image. I think the codes worked before. Where should I change in my codes?
[19/Apr/2016 21:09:27] "GET /static/myapp/image/resize/yu_popup.jpg HTTP/1.1" 404 1729
And I read some web pages which said we must use MEDIA_ROOT only in development environment, so I don't use MEDIA_ROOT. Is this problem caused because I don't use MEDIA_ROOT and should I use MEDIA_ROOT even when I release my application?
$ tree
.
|-- db
|   |-- myapp.sqlite3
|-- db.sqlite3
|-- myapp
|   |-- __init__.py
|   |-- admin.py
|   |-- apps.py
|   |-- forms.py
|   |-- media
|   |   `-- resize
|   |       `-- photo.JPG
|   |-- migrations
|   |   |-- 0001_initial.py
|   |   |-- 0002_resize.py
|   |-- models.py
|   |-- static
|   |   `-- myapp
|   |       |-- image
|   |       |   `-- resize
|   |       |       |-- yu_popup.jpg
|   |       `-- js
|   |-- templates
|   |   |-- base.html
|   |   `-- myapp
|   |       |-- resize
|   |       |   `-- resize.html
|   |-- tests.py
|   |-- urls.py
|   `-- views.py
|-- manage.py
|-- myproject
|   |-- __init__.py
|   |-- __pycache__
|   |-- settings.py
|   |-- urls.py
|   `-- wsgi.py
`-- static
    `-- myapp
        `-- image
            |-- resize
            |   |-- 1454049232616.jpg
            `-- resize_wHx2hQC
settings.py
# -*- coding: utf-8 -*-
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'myapp',
    'debug_toolbar',
    'social.apps.django_app.default',
]
MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    #'django.middleware.cache.UpdateCacheMiddleware',
    'django.middleware.common.CommonMiddleware',
    #'django.middleware.cache.FetchFromCacheMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'social.apps.django_app.middleware.SocialAuthExceptionMiddleware',
]
APP_DIR = os.path.join(BASE_DIR, 'myapp')
#STATIC_ROOT = os.path.join(APP_DIR, "staticroot")
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    #os.path.join(BASE_DIR, 'static'),
    os.path.join(APP_DIR, 'static'),
)
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    #'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
#MEDIA_ROOT = os.path.join(APP_DIR,"media")
#MEDIA_URL = '/media/'
views.py
def resize(request):
    #import pdb; pdb.set_trace()
    from myapp.forms import Resizef
    formset = Resizef
    photo = ""
    if request.method == 'POST':
        form = formset(request.POST)
        try:
            from myapp.models import Resize
            new_photo = Resize()
            new_photo.photo = request.FILES['photo']
            new_photo.save()
            photo = Resize.objects.get(id=new_photo.id)  # 
        except:
            pass
    else:
        form = formset()
    view = {'form': form, 'photo': photo}
    template = 'myapp/resize/resize.html'
    return render(request, template, view)
models.py
def resize_based_upload_to(instance, filename):
    return "static/myapp/image/resize/{}".format(filename)
@python_2_unicode_compatible  
class Resize(models.Model):
    photo = models.ImageField(upload_to=resize_based_upload_to)
    class Meta:
        db_table = traceback.extract_stack()[-2][2].lower()
resize.html
<html>
<body>
    <form action="" method="post" enctype="multipart/form-data">
    {% csrf_token %}
        {{ form.photo }}  <br />
        <button type="submit">
            <span>Upload</span>
        </button>  <br />
    </form>
    <h3>Upload Photo</h3>  <br />
    <img src="/{{ photo.photo }}" />  <br />
</body>
</html>
Python3.5, Django1.9
 
    