django,mezzanine,nginx中displayable_links.js出现500错误

时间:2016-02-01 17:59:56

标签: django mezzanine django-tinymce

我在displayable_links.js上收到500错误。我认为这是我的ssl设置。使用Django 1.9.1,Python 2.7.5,PostgreSQL 9.2.14和Mezzanine 4.1。发生在调试和枪支背后。我有*允许主机只是为了消除这种可能性。它也直接通过端口8000发生。

我的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/;
    }
}

}

我的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,
            },
        }
    }

编辑添加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

2 个答案:

答案 0 :(得分:1)

4.1版本发布后几天就已修复。因此,您需要立即使用master分支,直到4.1.1或4.2。

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

答案 1 :(得分:0)

我刚刚解决了这个问题。您只需要在应用程序的urls.py文件中覆盖URL端点的处理程序:“^ displayable_links.js $”。这是我做的:

创建自定义views.py以存储自定义处理函数:

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]))

然后,在您自己的应用的urls.py文件中。这是一个示例代码片段,现在适用于我:

# 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"),
]

请记住,在您执行此操作之前,此网址规则必须位于任何位置:

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

因为在Django URL调度程序中,排序确实很重要!

如果按照说明执行此操作,当您单击TinyMCE中的“添加链接”按钮时,它将由您的自定义处理程序处理,您应该能够毫无问题地添加指向您的博客/页面的链接。

注意:

  • 这只不过是一个黑客攻击,如果这对您不起作用或者您有更好的解决方案,请在下面发表评论。