我尝试使用Gunicorn和命令private bool IsAuthenticated(string[] roles)
{
// Should always fail if matcher is empty.
if (_allowedRoleMatcherTemplate == string.Empty)
{
return true;
}
...
运行我的项目,但是结果是错误,并且gunicorn取消了启动。
gunicorn --bind 0.0.0.0:8000 myproject.wsgi:application
这有什么问题?有什么修复方法吗?
答案 0 :(得分:0)
Devang Padhiyar,谢谢您的回答。让我们看看我的setting.py文件
import os
import datetime
from datetime import timedelta
import time
from django.utils.translation import ugettext_lazy as _
from django.conf.locale.en import formats as es_formats
from django.core.cache import cache
from django.core.validators import RegexValidator
from bs4 import BeautifulSoup
from django.urls import reverse_lazy
from easy_thumbnails.conf import Settings as thumbnail_settings
from django.core.files import File as FileWrapper
from django.shortcuts import redirect
from django.http import Http404
from django.contrib.messages import constants as message_constants
from core import get_shortcut, get_shortcut_setting
MESSAGE_LEVEL = message_constants.DEBUG
AUTH_USER_MODEL = 'auth.User'
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = '%h_=n$2yh554=2za0zsb%ubk!tg=e0)l@_w@ap#^d#_ew7)yig'
DEBUG = True
ALLOWED_HOSTS = ['0.0.0.0', '103.105.98.214', 'protek.id', 'demo.protek.id', 'localhost']
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
# =========================================================================================
# =========================================================================================
INSTALLED_APPS = [
'django.contrib.contenttypes',
'grappelli.dashboard',
'admin_shortcuts',
'dal',
'dal_select2',
'grappelli',
'django_admin_env_notice',
'django.contrib.admin',
'grappelli_autocomplete_fk_edit_link',
'el_pagination',
'crispy_forms', # http://django-crispy-forms.readthedocs.io/en/latest/install.html
'django_select2', # https://github.com/applegrew/django-select2
'easy_select2',
'easy_thumbnails', # https://github.com/SmileyChris/easy-thumbnails
'image_cropping',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django_admin_caching',
'user_sessions', # app/user_sessions/session/
'nested_admin', # inline multiple tree
'tabbed_admin', # tabbed jquery
'watchman', # monitor status database IPADDRESS/watchman/
'django.contrib.humanize', # Money formated for HTML
'mptt', # Tree
'sorl.thumbnail', # http://django-file-picker.readthedocs.io/en/latest/
'clear_cache', # python manage.py clear_cache
'cachetable', # database Cache /app/sysconf/cachetable/
'ckeditor', # editor
'dbbackup_ui', # Bakcup Db dan media | app/backups/backup-database-and-media/
'session_security', # http://django-session-security.readthedocs.io | Ipaddress/session_security/ping/
'reversion', # VersionAdmin data model
'reversion_compare', # https://github.com/jedie/django-reversion-compare
'debug_toolbar', # https://django-debug-toolbar.readthedocs.io
'djangobower', # Pendukung debug toolbar | https://axiacore.com/blog/effective-dependency-management-django-using-bower/
# 'export_action', # Download exel disetiap table model
'import_export', # http://django-import-export.readthedocs.io
'tagging',
'smart_selects', # Berhubungan dengan popup, get dll
'bidiutils', # Context processor
'pipeline', # https://django-pipeline.readthedocs.io/en/latest/installation.html
'django_postgrespool', # Postgres Connection Pooling backend
'djangosecure',
'treewidget',
# 'sysconf',
# 'moderation', # or 'moderation.apps.ModerationConfig',,
'django_pg_current_timestamp',
'django.contrib.sitemaps',
'robots', # https://godjango.com/23-robots-and-sitemaps/
'filer', # https://django-filer.readthedocs.io/en/latest/installation.html
'autofixture', # https://pypi.org/project/django-autofixture/
'corsheaders', # https://www.techiediaries.com/django-cors/
'django_nose',
'redisboard',
'core_doc',
'crm_mstdata',
'globalmasters',
'hris',
'hris_mstdata',
'crm',
'homepage',
'product',
# 'placement',
'facultative',
'finance',
'docman',
'treaty',
]
# =========================================================================================
# =========================================================================================
# BACKEND SETUP =========================================================================
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'user_sessions.middleware.SessionMiddleware',
'django_session_timeout.middleware.SessionTimeoutMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
'session_security.middleware.SessionSecurityMiddleware',
'x_forwarded_for.middleware.XForwardedForMiddleware',
'qinspect.middleware.QueryInspectMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
]
WSGI_APPLICATION = 'core.wsgi.application'
SESSION_ENGINE = 'user_sessions.backends.db'
SESSION_CACHE_ALIAS = "default"
ROOT_URLCONF = 'core.urls'
PASSWORD_HASHERS = [
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
]
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
# 'loggers': {
# 'django.db.backends': {
# 'level': 'DEBUG',
# 'handlers': ['console'],
# },
# 'qinspect': {
# 'handlers': ['console'],
# 'level': 'DEBUG',
# 'propagate': True,
# }
# },
}
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'cachetable',
},
}
# CACHES = {
# "default": {
# "BACKEND": "django_redis.cache.RedisCache",
# "LOCATION": "redis://127.0.0.1:6379/1",
# "OPTIONS": {
# "CLIENT_CLASS": "django_redis.client.DefaultClient"
# },
# "KEY_PREFIX": "brokr"
# },
# 'select2': {
# "BACKEND": "django_redis.cache.RedisCache",
# "LOCATION": "redis://127.0.0.1:6379/2",
# "OPTIONS": {
# "CLIENT_CLASS": "django_redis.client.DefaultClient",
# }
# }
# }
# SELECT2_CACHE_BACKEND = 'select2'
CACHE_TTL = 60 * 15
SESSION_COOKIE_AGE = 30 * 60 # 30 Menit
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
COMPRESS = True
COMPRESS_AUTO = True
COMPRESS_VERSION = True
COMPRESS_ENABLED = True
DATA_UPLOAD_MAX_NUMBER_FIELDS = None
# =========================================================================================
# =========================================================================================
# FRONT END SETUP =========================================================================
THUMBNAIL_PROCESSORS = (
'easy_thumbnails.processors.colorspace',
'easy_thumbnails.processors.autocrop',
'filer.thumbnail_processors.scale_and_crop_with_subject_location',
'easy_thumbnails.processors.filters',
'image_cropping.thumbnail_processors.crop_corners',
) + thumbnail_settings.THUMBNAIL_PROCESSORS
THUMBNAIL_ALIASES = {
'': {
'avatar': {'size': (50, 50), 'crop': True},
},
}
THUMBNAIL_HIGH_RESOLUTION = True
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates'),
],
'APP_DIRS': False,
'OPTIONS': {
'debug': DEBUG,
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'bidiutils.context_processors.bidi',
'django_admin_env_notice.context_processors.from_settings',
# 'context_processors.app_list',
],
'loaders': [
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'apptemplates.Loader',
]),
],
},
},
]
DYNAMIC_PREFERENCES = {
'MANAGER_ATTRIBUTE': 'preferences',
'REGISTRY_MODULE': 'dynamic_preferences_registry',
'ADMIN_ENABLE_CHANGELIST_FORM': False,
'SECTION_KEY_SEPARATOR': '__',
'ENABLE_CACHE': True,
'VALIDATE_NAMES': True,
}
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = '/media/'
LOGIN_URL = '/login/'
ADMIN_MEDIA_PREFIX = '/media/'
MEDIA_ROOT = os.path.join(SITE_ROOT, 'media')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "assets"),
)
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.CachedStaticFilesStorage'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'djangobower.finders.BowerFinder',
# 'compressor.finders.CompressorFinder',
'pipeline.finders.PipelineFinder',
)
BOWER_COMPONENTS_ROOT = '/PROJECT_ROOT/assets/bower_components/'
BOWER_PATH = '/usr/bin/bower'
BOWER_INSTALLED_APPS = (
'jquery',
'underscore',
'markitup#1.1.14',
'mediaelement#2.22.0',
'blueimp-file-upload#9.12.5',
)
PIPELINE = {
'PIPELINE_ENABLED': True,
'JS_COMPRESSOR': 'pipeline.compressors.yuglify.YuglifyCompressor',
'CSS_COMPRESSOR': 'pipeline.compressors.yuglify.YuglifyCompressor',
}
JS_WRAPPER = "(function(){stuff();%s})();"
CKEDITOR_UPLOAD_PATH = "uploads/"
CKEDITOR_CONFIGS = {
'default': {
'skin': 'moono-lisa',
'toolbar': [["Format", "Bold", "Italic", "Underline", "Strike", "SpellChecker", "Print"],
['NumberedList', 'BulletedList', "Indent", "Outdent", 'JustifyLeft',
'JustifyCenter','JustifyRight', 'JustifyBlock'],
["Image", "Table", "Link", "Unlink", "Anchor", "SectionLink",
"Subscript", "Superscript"], ['Undo', 'Redo'], ["Source"],
["Maximize"]],
'tabSpaces': 3,
'toolbarCanCollapse': True,
'width': 880,
},
}
CKEDITOR_ALLOW_NONIMAGE_FILES = False
# TABBED_ADMIN_USE_JQUERY_UI = True
# TABBED_ADMIN_JQUERY_UI_CSS = 'tabbed_admin/css/tabbed_grappelli_admin.css'
# TABBED_ADMIN_JQUERY_UI_JS = 'tabbed_admin/js/jquery-ui-1.11.4.min.js'
LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = '/'
UPLOADFILE = '/files/'
STATIC_DEPS = True
# TAGGIT_CASE_INSENSITIVE = True
DEFAULT_FILER_SERVERS = {
'private': {
'main': {
'ENGINE': 'filer.server.backends.default.DefaultServer',
},
'thumbnails': {
'ENGINE': 'filer.server.backends.default.DefaultServer',
}
}
}
# =====================================================================================
# =====================================================================================
# DATABASE SETUP ======================================================================
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'core',
'USER': 'postgres',
'PASSWORD': 'Kambing1',
'HOST': 'localhost',
'PORT': '5432',
'CONN_MAX_AGE': 60 * 10, # 10 minutes
'AUTOCOMMIT': True,
}
}
SOUTH_DATABASE_ADAPTERS = {
'default': 'south.db.postgresql_psycopg2'
}
DATABASE_POOL_ARGS = {
'max_overflow': 10,
'pool_size': 5,
'recycle': 300
}
# =========================================================================================
# =========================================================================================
# OTHER SETUP
VARNISH_MANAGEMENT_ADDRS = ('127.0.0.1:6082',)
es_formats.DATETIME_FORMAT = "Y-m-d H:i:s"
LANGUAGE_CODE = 'en-us'
LANGUAGE_BIDI = True
TIME_ZONE = 'Asia/Jakarta'
USE_I18N = True
USE_L10N = True
USE_TZ = True
SITE_ID = 1
GOOGLE_MAPS_API_KEY = 'AIzaSyD8BxyAFUwWxv2lUnFv06ekTakzTr3sl-E'
IMPORT_EXPORT_USE_TRANSACTIONS = True
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '316233965812-sjbuqlsaat19vesjo6fa44jrlidjit7d.apps.googleusercontent.com'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'ff-pKw85dbNjYxydjM5FTRxz'
# =========================================================================================
# =========================================================================================
# SECURTY UPDATE ========================================================================
X_FRAME_OPTIONS = 'DENY'
CORS_REPLACE_HTTPS_REFERER = False
HOST_SCHEME = "http://"
SECURE_PROXY_SSL_HEADER = None
SECURE_SSL_REDIRECT = False
SESSION_COOKIE_SECURE = False
CSRF_COOKIE_SECURE = False
SECURE_HSTS_SECONDS = None
SECURE_HSTS_INCLUDE_SUBDOMAINS = False
SECURE_FRAME_DENY = False
SECURE_BROWSER_XSS_FILTER = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_HSTS_PRELOAD = True
# =========================================================================================
# =========================================================================================
# EMAIL SETUP =============================================================================
EMAIL_BACKEND = 'django_multiple_email_backends.backend.CombinedEmailBackend'
EMAIL_BACKEND_LIST = ['django.core.mail.backends.filebased.EmailBackend',
'django.core.mail.backends.smtp.EmailBackend']
EMAIL_FILE_PATH = os.path.join(BASE_DIR, "sent_emails")
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'jasawarung@gmail.com'
EMAIL_HOST_PASSWORD = 'cgkxqhzuyfatucor'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
CONTACT_US_EMAIL = 'jasawarung@gmail.com'
# =========================================================================================
# =========================================================================================
# DEBUG TOOLBAR ===========================================================================
def show_toolbar(request):
return True
DEBUG_TOOLBAR_CONFIG = {
"SHOW_TOOLBAR_CALLBACK" : show_toolbar,
'DISABLE_PANELS': {
'debug_toolbar.panels.templates.TemplatesPanel',
'debug_toolbar.panels.redirects.RedirectsPanel',
},
}
DEBUG_TOOLBAR_PANELS = [
'debug_toolbar.panels.versions.VersionsPanel',
'debug_toolbar.panels.timer.TimerPanel',
'debug_toolbar.panels.settings.SettingsPanel',
'debug_toolbar.panels.headers.HeadersPanel',
'debug_toolbar.panels.request.RequestPanel',
'debug_toolbar.panels.sql.SQLPanel',
'debug_toolbar.panels.staticfiles.StaticFilesPanel',
'debug_toolbar.panels.templates.TemplatesPanel',
'debug_toolbar.panels.cache.CachePanel',
'debug_toolbar.panels.signals.SignalsPanel',
'debug_toolbar.panels.logging.LoggingPanel',
'debug_toolbar.panels.redirects.RedirectsPanel',
]
CONFIG_DEFAULTS = {
'RESULTS_CACHE_SIZE': 3,
'SHOW_COLLAPSED': True,
'SQL_WARNING_THRESHOLD': 100, # milliseconds
}
# =========================================================================================
# =========================================================================================
# THEME SETUP ============================================================================
GRAPPELLI_INDEX_DASHBOARD = 'core.dashboard.GlobalSetting'
GRAPPELLI_ADMIN_TITLE = 'BROKR PLATFORM'
GRAPPELLI_AUTOCOMPLETE_LIMIT = 20
GRAPPELLI_CLEAN_INPUT_TYPES = True
GRAPPELLI_SWITCH_USER = False
GRAPPELLI_SWITCH_USER_ORIGINAL = True
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
SESSION_EXPIRE_SECONDS = 3600 # 1 hour
SESSION_EXPIRE_AFTER_LAST_ACTIVITY = True
def itemDate():
return datetime.date.today()
ADMIN_SHORTCUTS = [
{
'title': 'Date Now : ' + str(itemDate()),
'shortcuts': [
{
'title': 'Home',
'url': '/',
},
{
'title': 'Treaty',
'url': '/treaty/',
'icon': 'clipboard',
# 'count_new': 'core.utils.count_submission',
},
{
'title': 'Facultative',
'url': '/facultative/',
'icon': 'paperclip',
# 'count_new': 'core.utils.count_submission',
},
{
'title': 'CRM',
'url': '/crm/',
'icon': 'address-book',
# 'count_new': 'core.utils.count_account',
},
# {
# 'title': 'Project',
# 'url': '/placement/',
# 'icon': 'folder',
# 'count_new': 'core.utils.count_submission',
# },
{
'title': 'HRD',
'url': '/hris/',
'icon': 'users',
# 'count_new': 'core.utils.count_account',
},
{
'title': 'Financial & Accounting',
'url': '/finance/',
'icon': 'chart-pie',
# 'count_new': 'core.utils.count_account',
},
# {
# 'title': 'Profile',
# 'url': '/hris/employeesadmin/',
# 'icon': 'user',
# },
]
},
]
ADMIN_SHORTCUTS_SETTINGS = {
'show_on_all_pages': True,
'hide_app_list': False,
'open_new_window': False,
}
CRISPY_TEMPLATE_PACK = 'uni_form'
APPEND_SLASH = False
LANGUAGES = (
('en', 'English'),
('pl', 'Polish'),
)
# MARKDOWN_DEUX_STYLES = {
# "default": {
# "extras": {
# "code-friendly": None,
# },
# "safe_mode": "escape",
# },
# }
# ROBOTS SETUP ============================================================================
ROBOTS_USE_SITEMAP = False
ROBOTS_SITEMAP_URLS = [
'http://103.105.98.211:8001/sitemap.xml',
]
ROBOTS_SITEMAP_VIEW_NAME = 'cached-sitemap'
ROBOTS_USE_HOST = False
ROBOTS_USE_SCHEME_IN_HOST = True
ROBOTS_CACHE_TIMEOUT = 60*60*24
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
CORS_ORIGIN_ALLOW_ALL = True
# EXPLORER_CONNECTIONS = { 'Default': 'default', 'Pws': 'pws' }
# EXPLORER_DEFAULT_CONNECTION = 'default'
# EXPLORER_TASKS_ENABLED = True
# EXPLORER_DEFAULT_ROWS = 5000
# EXPLORER_DATA_EXPORTERS = [('csv', 'explorer.exporters.CSVExporter'), ('excel', 'explorer.exporters.ExcelExporter'), ('json', 'explorer.exporters.JSONExporter')]
# EXPLORER_SQL_WHITELIST = ('CREATED', 'UPDATED', 'DELETED','REGEXP_REPLACE')
# EXPLORER_SQL_BLACKLIST = ('ALTER', 'RENAME ', 'DROP', 'TRUNCATE', 'INSERT INTO', 'UPDATE', 'REPLACE', 'DELETE', 'ALTER', 'CREATE TABLE', 'SCHEMA', 'GRANT', 'OWNER TO')
# EXPLORER_UNSAFE_RENDERING = True
# Whether the Query Inspector should do anything (default: False)
QUERY_INSPECT_ENABLED = True
# Whether to log the stats via Django logging (default: True)
QUERY_INSPECT_LOG_STATS = True
# Whether to add stats headers (default: True)
QUERY_INSPECT_HEADER_STATS = True
# Whether to log duplicate queries (default: False)
QUERY_INSPECT_LOG_QUERIES = True
# Whether to log queries that are above an absolute limit (default: None - disabled)
QUERY_INSPECT_ABSOLUTE_LIMIT = 100 # in milliseconds
# Whether to log queries that are more than X standard deviations above the mean query time (default: None - disabled)
QUERY_INSPECT_STANDARD_DEVIATION_LIMIT = 2
# Whether to include tracebacks in the logs (default: False)
QUERY_INSPECT_LOG_TRACEBACKS = True
# Project root (a list of directories, see below - default empty)
# QUERY_INSPECT_TRACEBACK_ROOTS = ['/path/to/my/django/project/']
ENVIRONMENT_NAME = "Production server"
ENVIRONMENT_COLOR = "#FF2222"
ENVIRONMENT_ADMIN_SELECTOR = "grp-header"
REDISBOARD_DETAIL_FILTERS = ['.*']
ADD_REVERSION_ADMIN=True
`