Apache django not saving image with image field in form
Question: I have a form which is working fine if I don't add any image, but it gives
template not found error as per the apache log if I try to upload image. The
problem here is that my form with image is working fine on my local server
(django) but not uploading the image when I start apache and run the project
in it.

This is my .conf file

    
    
    <VirtualHost *:80>
    WSGIScriptAlias / /home/anmol/suvidha.wsgi
    
    ServerName suvidha.com
    Alias /static /var/www/suvidha/register/static/
    
    <Directory /var/www/suvidha/>
    Order allow,deny  
    Allow from all
    </Directory>
    </VirtualHost>
    

My .wsgi file

    
    
    import os
    import sys
    sys.path = ['/var/www/suvidha'] + sys.path
    os.environ['DJANGO_SETTINGS_MODULE'] = 'suvidha.settings'
    import django.core.handlers.wsgi
    application = django.core.handlers.wsgi.WSGIHandler()
    

My .settings file

    
    
    # Absolute filesystem path to the directory that will hold user-uploaded files.
    # Example: "/home/media/media.lawrence.com/media/"
    MEDIA_ROOT = join(BASE_DIR, 'register/static')
    
    # URL that handles the media served from MEDIA_ROOT. Make sure to use a
    # trailing slash.
    # Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
    MEDIA_URL = '/static/images/'
    
    # Absolute path to the directory static files should be collected to.
    # Don't put anything in this directory yourself; store your static files
    # in apps' "static/" subdirectories and in STATICFILES_DIRS.
    # Example: "/home/media/media.lawrence.com/static/"
    STATIC_ROOT = ''
    
    # URL prefix for static files.
    # Example: "http://media.lawrence.com/static/"
    STATIC_URL = '/static/'
    
    # Additional locations of static files
    STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    )
    
    # List of finder classes that know how to find static files in
    # various locations.
    STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    #'django.contrib.staticfiles.finders.DefaultStorageFinder',
     )
    

My directories listing

    
    
    /var
      /www
        /suvidha
          /register
             /static
    

Log file

    
    
    [Tue Apr 22 00:23:53 2014] [error] [client 192.168.58.196] mod_wsgi (pid=15679):Exception occurred processing WSGI script '/home/byld/suvidha.wsgi'.
    [Tue Apr 22 00:23:53 2014] [error] [client 192.168.58.196] Traceback (most recent call last):
    [Tue Apr 22 00:23:53 2014] [error] [client 192.168.58.196]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 241, in __call__
    [Tue Apr 22 00:23:53 2014] [error] [client 192.168.58.196]     response = self.get_response(request)
    [Tue Apr 22 00:23:53 2014] [error] [client 192.168.58.196]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 153, in get_response
    [Tue Apr 22 00:23:53 2014] [error] [client 192.168.58.196]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
    [Tue Apr 22 00:23:53 2014] [error] [client 192.168.58.196]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 228, in handle_uncaught_exception
    [Tue Apr 22 00:23:53 2014] [error] [client 192.168.58.196]     return callback(request, **param_dict)
    [Tue Apr 22 00:23:53 2014] [error] [client 192.168.58.196]   File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py", line 91, in _wrapped_view
    [Tue Apr 22 00:23:53 2014] [error] [client 192.168.58.196]     response = view_func(request, *args, **kwargs)
    [Tue Apr 22 00:23:53 2014] [error] [client 192.168.58.196]   File "/usr/local/lib/python2.7/dist-packages/django/views/defaults.py", line 32, in server_error
    [Tue Apr 22 00:23:53 2014] [error] [client 192.168.58.196]     t = loader.get_template(template_name) # You need to create a 500.html template.
    [Tue Apr 22 00:23:53 2014] [error] [client 192.168.58.196]   File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py", line 145, in get_template
    [Tue Apr 22 00:23:53 2014] [error] [client 192.168.58.196]     template, origin = find_template(template_name)
    [Tue Apr 22 00:23:53 2014] [error] [client 192.168.58.196]   File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py", line 138, in find_template
    [Tue Apr 22 00:23:53 2014] [error] [client 192.168.58.196]     raise TemplateDoesNotExist(name)
    [Tue Apr 22 00:23:53 2014] [error] [client 192.168.58.196] TemplateDoesNotExist: 500.html
    

It would be great if someone can help, I am stuck on this and can't find any
answer.


Answer: What this is telling you is that you have an exception somewhere triggered by
the image upload, which would normally result in a 500 error response - but
you have no 500.html template to use to display the response. Create the
relevant template, and you'll be able to see the real bug.

