阿拉伯语文本在Django中显示不正确但正确显示n终端

时间:2016-11-05 05:43:21

标签: python mysql django nginx character-encoding

我有一个mysql数据库,其中包含一个带有阿拉伯语文本的表。当我在终端中查询它时它显示正确,但是当我想在Django管理面板中看到它时,它显示混乱的文本,如“ييÙÙَسÙÙسÙÙŠØμÙدÙرÙأنÙ'اؓ 我正在使用Django 1.10 mysql Ver 14.14 Distrib 5.7.16,对于Linux(x86_64)使用EditLine wrappermy和nginx。我的配置和表格如下:

CREATE DATABASE `q` /*!40100 DEFAULT CHARACTER SET utf8 */

CREATE TABLE `main_qsimplemin` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `SID` smallint(6) NOT NULL,
  `VID` smallint(6) NOT NULL,
  `AText` longtext COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `main_quransimplemin_SID_8789f31f_uniq` (`SID`,`VID`)
) ENGINE=InnoDB AUTO_INCREMENT=6238 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci 

Mysql配置:

[mysqld]
#init_connect=‘SET collation_connection = utf8_unicode_ci’
#init_connect=‘SET NAMES utf8’
#character-set-server=utf8
#collation-server=utf8_unicode_ci
#skip-character-set-client-handshake

#default-character-set=utf8
character-set-server = utf8

[client]
port        = 3306
socket      = /var/run/mysqld/mysqld.sock

#character-set-client = utf8

[mysqld_safe]
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp

collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8


sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

symbolic-links=0

!includedir /etc/mysql/conf.d/

Django配置:

# -*- coding: utf-8 -*-
"""
Django settings for quran project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'ecdh^6f6%2(2#lr=h5&+do@dwi*dxs7@@f=m0$!)oq3@f2*l!k'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

#TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'main',
    'words',
)

MIDDLEWARE_CLASSES = (
    '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',
)

ROOT_URLCONF = 'qu.urls'

WSGI_APPLICATION = 'qu.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': "q",
        'USER': 'q',
        'PASSWORD': 'xxxxxx',
        'HOST': 'qdb',
#        'OPTIONS': {
#                 "init_command": "SET foreign_key_checks = 0;",
#            },
    }
}
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
            "django.contrib.auth.context_processors.auth",
            ],
            'debug': DEBUG
        }
    },
]
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(__file__), 'static/')

感谢您的帮助

0 个答案:

没有答案