Forums

Server Error 500

Hi guys,

I have a simple blog project. When I go to my domain www.nomadpad.io I get "Server Error 500"

From the error log below, it appears to be something to do with my editedimage field, which looks like this in my models.py :

editedimage = ProcessedImageField(upload_to="images", blank=True, null=True,
                            processors = [Transpose()],
                            format="JPEG")

This all works fine in my development environment. I can still access my live django-admin page, and when I try to upload an image, when I save the post, it returns again the Server Error 500.

2018-02-25 04:19:37,291: Internal Server Error: /#012Traceback (most recent call last):#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 882, in _resolve_lookup#012 current = current[bit]#012TypeError: 'ProcessedImageFieldFile' object is not subscriptable#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner#012 response = get_response(request)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response#012 response = self.process_exception_by_middleware(e, request)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response#012 response = wrapped_callback(request, callback_args, callback_kwargs)#012 File "/home/DMells123/nomadpad/posts/views.py", line 24, in getAllPosts#012 return render(request, 'posts/getAllPosts.html', context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/shortcuts.py", line 30, in render#012 content = loader.render_to_string(template_name, context, request, using=using)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/loader.py", line 68, in render_to_string#012 return template.render(context, request)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/backends/django.py", line 66, in render#012 return self.template.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 207, in render#012 return self._render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 199, in _render#012 return self.nodelist.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 990, in render#012 bit = node.render_annotated(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 957, in render_annotated#012 return self.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/loader_tags.py", line 177, in render#012 return compiled_parent._render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 199, in _render#012 return self.nodelist.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 990, in render#012 bit = node.render_annotated(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 957, in render_annotated#012 return self.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/loader_tags.py", line 72, in render#012 result = block.nodelist.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 990, in render#012 bit = node.render_annotated(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 957, in render_annotated#012 return self.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/defaulttags.py", line 322, in render#012 return nodelist.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 990, in render#012 bit = node.render_annotated(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 957, in render_annotated#012 return self.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/defaulttags.py", line 216, in render#012 nodelist.append(node.render_annotated(context))#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 957, in render_annotated#012 return self.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 1040, in render#012 output = self.filter_expression.resolve(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 708, in resolve#012 obj = self.var.resolve(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 849, in resolve#012 value = self._resolve_lookup(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 890, in _resolve_lookup#012 current = getattr(current, bit)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/db/models/fields/files.py", line 69, in url#012 self._require_file()#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/db/models/fields/files.py", line 46, in _require_file#012 raise ValueError("The '%s' attribute has no file associated with it." % self.field.name)#012ValueError: The 'editedimage' attribute has no file associated with it. 2018-02-25 04:19:41,460: Internal Server Error: /#012Traceback (most recent call last):#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 882, in _resolve_lookup#012 current = current[bit]#012TypeError: 'ProcessedImageFieldFile' object is not subscriptable#012#012During handling of the above exception, another exception occurred:#012#012Traceback (most recent call last):#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner#012 response = get_response(request)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response#012 response = self.process_exception_by_middleware(e, request)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response#012 response = wrapped_callback(request, callback_args, **callback_kwargs)#012 File "/home/DMells123/nomadpad/posts/views.py", line 24, in getAllPosts#012 return render(request, 'posts/getAllPosts.html', context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/shortcuts.py", line 30, in render#012 content = loader.render_to_string(template_name, context, request, using=using)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/loader.py", line 68, in render_to_string#012 return template.render(context, request)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/backends/django.py", line 66, in render#012 return self.template.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 207, in render#012 return self._render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 199, in _render#012 return self.nodelist.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 990, in render#012 bit = node.render_annotated(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 957, in render_annotated#012 return self.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/loader_tags.py", line 177, in render#012 return compiled_parent._render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 199, in _render#012 return self.nodelist.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 990, in render#012 bit = node.render_annotated(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 957, in render_annotated#012 return self.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/loader_tags.py", line 72, in render#012 result = block.nodelist.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 990, in render#012 bit = node.render_annotated(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 957, in render_annotated#012 return self.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/defaulttags.py", line 322, in render#012 return nodelist.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 990, in render#012 bit = node.render_annotated(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 957, in render_annotated#012 return self.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/defaulttags.py", line 216, in render#012 nodelist.append(node.render_annotated(context))#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 957, in render_annotated#012 return self.render(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 1040, in render#012 output = self.filter_expression.resolve(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 708, in resolve#012 obj = self.var.resolve(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 849, in resolve#012 value = self._resolve_lookup(context)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/template/base.py", line 890, in _resolve_lookup#012 current = getattr(current, bit)#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/db/models/fields/files.py", line 69, in url#012 self._require_file()#012 File "/home/DMells123/.virtualenvs/nomadpadvenv/lib/python3.6/site-packages/django/db/models/fields/files.py", line 46, in _require_file#012 raise ValueError("The '%s' attribute has no file associated with it." % self.field.name)#012ValueError: The 'editedimage' attribute has no file associated with it.

My settings files look like this :

base.py

import os from decouple import config from unipath import Path

PROJECT_DIR = Path(file).parent.parent.parent

STATIC_ROOT = os.path.join(PROJECT_DIR,'posts/static') STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(PROJECT_DIR,'static'), )

MEDIA_DIR = os.path.join(PROJECT_DIR,'posts/media') MEDIA_ROOT = MEDIA_DIR MEDIA_URL = '/media/'

ROOT_DIR = PROJECT_DIR

TEMPLATE_DIR = os.path.join(PROJECT_DIR, 'posts/templates')

CKEDITOR_UPLOAD_PATH = MEDIA_ROOT CKEDITOR_IMAGE_BACKEND = 'pillow'

CKEDITOR_JQUERY_URL = 'https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js'

CKEDITOR_UPLOAD_PATH = 'uploads/' CKEDITOR_IMAGE_BACKEND = "pillow" CKEDITOR_CONFIGS = { 'default': { 'toolbar': 'full', 'extraPlugins' : 'image2', } }

DEBUG = config('DEBUG', default=False, cast=bool) SECRET_KEY = * --SECRET_KEY = config('SECRET_KEY')

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'nomadpaddb', 'USER': 'super', 'PASSWORD': '****', # 'PASSWORD': config('DB_PASSWORD'), 'HOST': 'DMells123-678.postgres.pythonanywhere-services.com', 'PORT':'10678', } }

INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', #provides access to the provided authentication systemm 'django.contrib.contenttypes', # used by the auth app to track models installed in your database. 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'posts', 'social_django', 'ckeditor', 'ckeditor_uploader', 'imagekit', 'django_archive', ]

MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'social_django.middleware.SocialAuthExceptionMiddleware', ]

ROOT_URLCONF = 'blog.urls'

TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [TEMPLATE_DIR,], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', 'django.template.context_processors.media', # <-- to process media files 'social_django.context_processors.backends', # <-- for OAuth 'social_django.context_processors.login_redirect', # <-- for OAuth ], }, }, ]

WSGI_APPLICATION = 'blog.wsgi.application'

AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 'OPTIONS': {'min_length': 6, } }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ]

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Europe/London'

USE_I18N = True

USE_L10N = True

USE_TZ = True

LOGIN_URL = 'login' LOGOUT_URL = 'logout' LOGIN_REDIRECT_URL = 'home/'

AUTHENTICATION_BACKENDS = ( 'social_core.backends.twitter.TwitterOAuth', 'social_core.backends.facebook.FacebookOAuth2', 'django.contrib.auth.backends.ModelBackend', )

development.py

from .base import *

DEBUG = True

ALLOWED_HOSTS = []

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'travelblogdb', 'USER': 'dmells', 'PASSWORD': '****', 'HOST': 'localhost', 'PORT':'', } }

production.py

from .base import * from decouple import config

DEBUG = False

ALLOWED_HOSTS = ['www.nomadpad.io']

Are you sure that you're using all the same libraries with the same versions as you're using locally?

Hi Glenn,

Locally I did pip freeze > requirement.txt,

and then in my dev environment I just did pip install -r requirement.txt so it should all be the same right?

Thanks

deleted edit here. gitignore tidied up, and no longer getting commit issues, but still server error 500

Going to your domain, I don't see a server error 500?

Hi Conrad, I realised the problem was with my imagekit package. I removed the below field from my models, and now I can see my domain, but without the css processing:

editedimage = ProcessedImageField(upload_to="images", null=True, processors = [Transpose()], format="JPEG")

But i really would like this, because I can't get ckeditor to keep my pictures rotated correctly!

Thanks

Do you mean that this line:

editedimage = ProcessedImageField(upload_to="images", null=True, processors = [Transpose()], format="JPEG")

is erroring? If so, what is the error message?

Hi Conrad, I figured out that it was because the images being saved to that field in development weren't being transferred across to production. So once I re-uploaded them in production I don't get the error any more.

Only thing left now is that my CSS isn't working! I've ran collectstatic, and still nothing, no images either.

Your static file mappings are wrong. Re-read this.