3

I am getting a 500 error on displayable_links.js. I assume it is something with my ssl setup. Using Django 1.9.1, Python 2.7.5, PostgreSQL 9.2.14, and Mezzanine 4.1. Happens in debug and behind gunicorn. I have * for allowed hosts just to eliminate that as a possibility. It also happens directly over port 8000.

My nginc.conf:

 worker_processes  1;
error_log  /var/log/nginx/error.log;
error_log   /var/log/nginx/error.log  notice;
error_log   /var/log/nginx/error.log  info;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

server {
    listen       80  default_server;
    root  /opt/www/;
    return 301 https://www2.example.com$request_uri;
    gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
}
server {
    listen       443 ssl;
    server_name  www2.example.com;
    add_header X-Frame-Options SAMEORIGIN;
    server_name_in_redirect off;
     root  /opt/www/;
    gzip off;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain
               text/css
               application/json
               application/javascript
               application/x-javascript
               text/xml
               application/xml
               application/xml+rss
               text/javascript;
    ssl_certificate      /etc/httpd/conf.d/2016.example.com.crt;
    ssl_certificate_key  /etc/httpd/conf.d/2016.example.com.key;
    ssl_trusted_certificate /etc/httpd/conf.d/intermediate.crt;
    ssl_dhparam /etc/httpd/conf.d/dhparams.pem;
    add_header Strict-Transport-Security max-age=31536000;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
    ssl_buffer_size 8k;
    ssl_session_cache shared:SSL:30m;
    ssl_session_timeout 30m;
    ssl_stapling on;
    resolver 8.8.8.8;
    ssl_stapling_verify on;

    ssl_prefer_server_ciphers  on;
    proxy_redirect off;
    location / {
         proxy_pass http://127.0.0.1:8000;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    location /static/ {
         autoindex on;
         root /opt/www/;
    }
}

}

And my settings.py:

from __future__ import absolute_import, unicode_literals
enter code here`enter code here`import os
    from django.utils.translation import ugettext_lazy as _
    SEARCH_MODEL_CHOICES = []
    PAGE_MENU_TEMPLATES = (
         (1, _("Top navigation bar"), "pages/menus/dropdown.html"),
         (2, _("Left-hand tree"), "pages/menus/tree.html"),
         (3, _("Footer"), "pages/menus/footer.html"),
    )
    PAGE_MENU_TEMPLATES_DEFAULT = (2,)
    USE_MODELTRANSLATION = False
    ALLOWED_HOSTS = ['*']
    SERVER_EMAIL = 'server@example.com'
    ADMINS = [('example', 'example@example.com'),]
    TIME_ZONE = 'UTC'
    USE_TZ = True
    LANGUAGE_CODE = "en"
    LANGUAGES = (
        ('en', _('English')),
    )
    SITE_TITLE = "example Systems"
    DEBUG = False
    SESSION_EXPIRE_AT_BROWSER_CLOSE = True
    SITE_ID = 1
    USE_I18N = False
    AUTHENTICATION_BACKENDS = ("mezzanine.core.auth_backends.MezzanineBackend",)
    FILE_UPLOAD_PERMISSIONS = 0o644
    DATABASES = {
        "default": {
            "ENGINE": "django.db.backends.postgresql",
            "NAME": "example",
            "USER": "example",
            "PASSWORD": "example",
            "HOST": "127.0.0.1",
            "PORT": "5432",
        }
    }
    PROJECT_APP_PATH = os.path.dirname(os.path.abspath(__file__))
    PROJECT_APP = os.path.basename(PROJECT_APP_PATH)
    PROJECT_ROOT = BASE_DIR = os.path.dirname(PROJECT_APP_PATH)
    CACHE_MIDDLEWARE_KEY_PREFIX = PROJECT_APP
    STATIC_URL = "https://www2.example.com/static/"
    STATIC_ROOT = "/opt/www/static/"

    MEDIA_URL = STATIC_URL + "media/"
    MEDIA_ROOT = os.path.join(PROJECT_ROOT, *MEDIA_URL.strip("/").split("/"))
    ROOT_URLCONF = "%s.urls" % PROJECT_APP
    TEMPLATES = [{u'APP_DIRS': True,
                  u'BACKEND': u'django.template.backends.django.DjangoTemplates',
                  u'DIRS': (u'/opt/www/modernbiz/theme/templates', u'/opt/www/templates'),
                  u'OPTIONS': {u'builtins': [u'mezzanine.template.loader_tags'],
                               u'context_processors': (u'django.contrib.auth.context_processors.auth',
                                                       u'django.contrib.messages.context_processors.messages',
                                                       u'django.core.context_processors.debug',
                                                       u'django.core.context_processors.i18n',
                                                       u'django.core.context_processors.static',
                                                       u'django.core.context_processors.media',
                                                       u'django.core.context_processors.request',
                                                       u'django.core.context_processors.tz',
                                                       u'mezzanine.conf.context_processors.settings',
                                                       u'mezzanine.pages.context_processors.page')}}]
    INSTALLED_APPS = (
        "modernbiz",
        "django.contrib.admin",
        "django.contrib.auth",
        "django.contrib.contenttypes",
        "django.contrib.redirects",
        "django.contrib.sessions",
        "django.contrib.sites",
        "django.contrib.sitemaps",
        "django.contrib.staticfiles",
        "mezzanine.boot",
        "mezzanine.conf",
        "mezzanine.core",
        "mezzanine.generic",
        "mezzanine.pages",
        "mezzanine.blog",
        "mezzanine.forms",
        "mezzanine.galleries",
        "mezzanine.twitter",
        "howtos",
        "mezzanine.accounts",
        "mezzanine.mobile",
        "polls",
    )
    MIDDLEWARE_CLASSES = (
        "django.middleware.gzip.GZipMiddleware",
        'htmlmin.middleware.MarkRequestMiddleware',
        "mezzanine.core.middleware.UpdateCacheMiddleware",
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
        'django.middleware.clickjacking.XFrameOptionsMiddleware',
        "mezzanine.core.request.CurrentRequestMiddleware",
        "mezzanine.core.middleware.RedirectFallbackMiddleware",
        "mezzanine.core.middleware.TemplateForDeviceMiddleware",
        "mezzanine.core.middleware.TemplateForHostMiddleware",
        "mezzanine.core.middleware.AdminLoginInterfaceSelectorMiddleware",
        "mezzanine.core.middleware.SitePermissionMiddleware",
        "mezzanine.pages.middleware.PageMiddleware",
        "mezzanine.core.middleware.FetchFromCacheMiddleware",
    )
    PACKAGE_NAME_FILEBROWSER = "filebrowser_safe"
    PACKAGE_NAME_GRAPPELLI = "grappelli_safe"
    OPTIONAL_APPS = (
        "debug_toolbar",
        "django_extensions",
        "compressor",
        PACKAGE_NAME_FILEBROWSER,
        PACKAGE_NAME_GRAPPELLI,
    )
    f = os.path.join(PROJECT_APP_PATH, "local_settings.py")
    if os.path.exists(f):
        exec(open(f, "rb").read())
    try:
        from mezzanine.utils.conf import set_dynamic_settings
    except ImportError:
        pass
    else:
        set_dynamic_settings(globals())
    SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTOCOL', 'https')
    COMPRESS_ENABLED = True
    COMPRESS_OFFLINE = True
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': True,
        'formatters': {
            'verbose': {
                'format': '%(asctime)s %(levelname)s [%(name)s:%(lineno)s] %(module)s %(process)d %(thread)d %(message)s'
            }
        },
        'handlers': {
            'file': {
                'level': 'DEBUG',
                'class': 'logging.FileHandler',
                'formatter': 'verbose',
                'filename': '/var/log/gunicorn/gunicorn.errors',
            }
        },
        'loggers': {
            'django.errors': {
                'level': 'DEBUG',
                'handlers': ['file'],
                'propagate': True,
            },
        }
    }

Edited to add the stacktrace:

Internal Server Error: /displayable_links.js
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib64/python2.7/site-packages/mezzanine/core/views.py", line 192, in displayable_links_js
    for url, obj in Displayable.objects.url_map(for_user=request.user).items():
  File "/usr/lib64/python2.7/site-packages/mezzanine/core/managers.py", line 366, in url_map
    home = self.model(title=_("Home"))
  File "/usr/lib/python2.7/site-packages/django/db/models/base.py", line 408, in __init__
    val = field.get_default()
  File "/usr/lib/python2.7/site-packages/django/db/models/fields/related.py", line 902, in get_default
    if isinstance(field_default, self.remote_field.model):
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types
[01/Feb/2016 20:50:25] "GET /displayable_links.js HTTP/1.0" 500 6309
nowen
  • 196
  • 1
  • 5
  • Could you please post the error message (stacktrace), that would be really helpful. – Jingo Feb 01 '16 at 18:46
  • I am not getting a stacktrace or an email. Just: [01/Feb/2016 18:06:45] "GET /displayable_links.js HTTP/1.0" 500 6467 – nowen Feb 01 '16 at 18:55
  • ok - I deleted the logging paramaters and got the stacktrace via the command line. ;-) – nowen Feb 01 '16 at 20:58
  • UPDATE - seems to be caused by a browser cache setting for javascript. turning it off and using incognito mode was required to find it. – nowen Feb 01 '16 at 22:43

2 Answers2

1

It has been fixed a few days ago after the 4.1 release. So you need to use the master branch for now until 4.1.1 or 4.2.

https://github.com/stephenmcd/mezzanine/pull/1516

yomguy
  • 66
  • 3
0

I just resolved this issue with a little hack. All you need is to override the handler of URL endpoint: "^displayable_links.js$" inside your app's urls.py file. Here is what I did:

Create a custom views.py to store your custom handler function:

from django.http import (HttpResponse)
from json import  dumps

def editor_link_handler(request):
    links = []
    sorted_links = sorted(links, key=lambda link: (link[0], link[1]['value']))
    return HttpResponse(dumps([link[1] for link in sorted_links]))

Then, inside your own app's urls.py file. Here is an example code snippet which works for me now:

# urls.py // Skip to the "Important" section for my custom code
from __future__ import unicode_literals

from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.views.i18n import set_language

import mezzanine
from mezzanine.core.views import direct_to_template
from mezzanine.conf import settings
from mezzanine.blog.views import blog_post_list

############################
### Important #########
##### Here is my cusom view function to handle the request
##############
from views import editor_link_handler

urlpatterns = i18n_patterns(
    # Change the admin prefix here to use an alternate URL for the
    # admin interface, which would be marginally more secure.
    url("^admin/", include(admin.site.urls)),
)
##################
###Important:#######
##### Here comes the serious stuff (my custom code)
###############

urlpatterns += [
    url("^displayable_links.js$", editor_link_handler,
        name="editor_link_handler"),
]

Remember this url rule needs to be anywhere BEFORE you do:

url("^", include("mezzanine.urls")),

Because in Django URL dispatchers, ordering does matter!

If you did this as instructed, when you click the "add link" button in TinyMCE, it will be handled by your custom handler, and you should be able to add links to your blog/page without a problem.


NOTE:

  • This is nothing more than a hack, please comment below if this doesn't work for you or that you have a better solution.
benjaminz
  • 3,118
  • 3
  • 35
  • 47