我正在使用 django 1.8 和 mongoengine 制作一个应用程序 但是当我尝试配置 Django setting.py 文件以使用虚拟数据库时,我收到以下错误
(orahienv) somya@somya-Inspiron-15-3555:/var/www/html/admin_python$ python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
July 06, 2017 - 16:57:25
Django version 1.8, using settings 'admin_python.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Performing system checks...
System check identified no issues (0 silenced).
July 06, 2017 - 17:00:15
Django version 1.8, using settings 'admin_python.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
<WSGIRequest: GET '/auth/login/?next=/'>
Internal Server Error: /auth/login/
Traceback (most recent call last):
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 164, in get_response
response = response.render()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/template/response.py", line 158, in render
self.content = self.rendered_content
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/template/response.py", line 135, in rendered_content
content = template.render(context, self._request)
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/template/backends/django.py", line 74, in render
return self.template.render(context)
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/template/base.py", line 208, in render
with context.bind_template(self):
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/template/context.py", line 235, in bind_template
updates.update(processor(self.request))
File "/var/www/html/admin_python/admin_app/context_processors.py", line 30, in init_menu
if request.user.is_authenticated():
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/utils/functional.py", line 226, in inner
self._setup()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/utils/functional.py", line 359, in _setup
self._wrapped = self._setupfunc()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/contrib/auth/middleware.py", line 22, in <lambda>
request.user = SimpleLazyObject(lambda: get_user(request))
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/contrib/auth/middleware.py", line 10, in get_user
request._cached_user = auth.get_user(request)
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 174, in get_user
user = backend.get_user(user_id)
File "/var/www/html/admin_python/admin_app/backend.py", line 29, in get_user
return TblAdmin.objects.get(pk=user_id)
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/query.py", line 328, in get
num = len(clone)
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/query.py", line 144, in __len__
self._fetch_all()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/query.py", line 965, in _fetch_all
self._result_cache = list(self.iterator())
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/query.py", line 238, in iterator
results = compiler.execute_sql()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 818, in execute_sql
sql, params = self.as_sql()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 367, in as_sql
extra_select, order_by, group_by = self.pre_sql_setup()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 48, in pre_sql_setup
self.setup_query()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 39, in setup_query
self.select, self.klass_info, self.annotation_col_map = self.get_select()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 216, in get_select
ret.append((col, self.compile(col, select_format=True), alias))
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 346, in compile
sql, params = node.as_sql(self, self.connection)
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/expressions.py", line 611, in as_sql
return "%s.%s" % (qn(self.alias), qn(self.target.column)), []
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 337, in quote_name_unless_alias
r = self.connection.ops.quote_name(name)
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/backends/dummy/base.py", line 21, in complain
raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
[06/Jul/2017 17:00:21]"GET /auth/login/?next=/ HTTP/1.1" 500 206077
我知道以前有人问过类似的问题。但这全都与发动机值(value)有关。有谁知道如何使用 NAME 值解决此错误?
设置.py -
import os
import admin_app
from django.utils import timezone
import mongoengine
"""from mongoengine import connect
connect('pom')"""
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'uj8$6(ol=!w)b3-luqzb=#6(j19gkbrnp2asq6=xt%5*s2ylz('
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
SPATIALITE_LIBRARY_PATH = 'mod_spatialite'
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'admin_app',
'celery', #http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html#using-the-django-orm-cache-as-a-result-backend
)
MIDDLEWARE_CLASSES = (
'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',
'django.middleware.security.SecurityMiddleware',
'djangoflash.middleware.FlashMiddleware',
#'django.middleware.cache.CacheMiddleware', #http://stackoverflow.com/a/658583/2546013
)
ROOT_URLCONF = 'admin_python.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates'), os.path.join(BASE_DIR, 'media')],
'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',
'admin_app.context_processors.init_menu',
'admin_app.context_processors.server_urls',
'djangoflash.context_processors.flash',
],
},
},
]
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
MEDIA_URL = '/media/'
HOST_URL='http://127.0.0.1:8001/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media/")
WSGI_APPLICATION = 'admin_python.wsgi.application'
STATIC_URL = '/static/'
SERVER_URL = 'http://localhost:8001/'
WEBAPP_URL = 'http://localhost/webapp_angular/'
USERAPI_URL = 'http://localhost:8000/'
HOST_URL_NEW='http://localhost:8001/media/'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
"""
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'admin_db',
'USER': 'root',
'PASSWORD': 'root',
'HOST': 'localhost',
}
}"""
"""DATABASES = {
'default': {
'ENGINE': 'django.db.backends.dummy',
}
}
"""
"""
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.dummy',
'NAME': 'pom',
'USER': 'root',
'PASSWORD': 'root',
'HOST': 'localhost',
}
}
from mongoengine import connect
connect('pom', username='root', password='root')"""
DATABASES = {
'default': {
'ENGINE': '',
},
}
_MONGODB_USER = 'root'
_MONGODB_PASSWD = 'root'
_MONGODB_HOST = 'localhost'
_MONGODB_NAME = 'pom'
_MONGODB_DATABASE_HOST = \
'mongodb://%s:%s@%s/%s' \
% (_MONGODB_USER, _MONGODB_PASSWD, _MONGODB_HOST, _MONGODB_NAME)
mongoengine.connect(_MONGODB_NAME, host=_MONGODB_DATABASE_HOST)
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = False
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
REST_FRAMEWORK = {
# other settings...
'DEFAULT_AUTHENTICATION_CLASSES': [],
'DEFAULT_PERMISSION_CLASSES': [],
}
LOGIN_URL = '/auth/login/'
LOGIN_REDIRECT_URL = '/'
AUTHENTICATION_BACKENDS = (
'admin_app.backend.AuthBackend',
'django.contrib.auth.backends.ModelBackend',
)
AUTH_USER_MODEL = 'admin_app.TblAdmin'
EMAIL_HOST = 'email-smtp.us-east-1.amazonaws.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'AKIAJB6VACOVZANVTC5A'
EMAIL_HOST_PASSWORD = 'Atu9qbV+X5aiwIlQzVAOVjU/AxkxMDV3X0l0FLWweSn9'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'support@doctorinsta.com'
#LOGGING SETTING
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format' : "[%(asctime)s] %(levelname)s [%(filename)s:%(funcName)s:%(lineno)s] %(message)s",
'datefmt' : "%d/%b/%Y %H:%M:%S"
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'applogfile': {
'level':'DEBUG',
'class':'logging.FileHandler',
'filename': os.path.join(BASE_DIR, 'drinsta.log'),
'formatter': 'verbose'
},
},
'loggers': {
'django.request': {
'level': 'ERROR',
'propagate': True,
'handlers': ['applogfile',],
},
'drinsta': {
'handlers': ['applogfile',],
'level': 'DEBUG',
},
}
}
#https://docs.djangoproject.com/en/1.8/topics/http/sessions/#configuring-the-session-engine
#https://github.com/dlrust/python-memcached-stats
#We can use the following command to see the keys:
# python -m memcached_stats 127.0.0.1 11211
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
'TIMEOUT' : 300 #Default
}
}
CACHE_BACKEND = 'memcached://127.0.0.1:11211/'
SESSION_ENGINE= 'django.contrib.sessions.backends.cache'
'''
RabbitMQ configurations begins
'''
#OLD FORMAT:
# BROKER_HOST = "127.0.0.1"
# BROKER_PORT = 5672 # default RabbitMQ listening port
# BROKER_USER = "admin"
# BROKER_PASSWORD = "admin"
# BROKER_VHOST = "admin" #Virtual hosts provide a way to segregate applications using the same RabbitMQ instance. Different users can have different access privileges to different vhost and queues and exchanges can be created so they only exists in one vhost.
#NEW FORMAT:
BROKER_URL = 'amqp://admin:admin@localhost:5672/admin'
'''
RabbitMQ configurations ends
'''
'''
Celery configurations begins
'''
#CELERY_BACKEND = "amqp" # telling Celery to report the results back to RabbitMQ
#'amqp' means Advanced Message Queuing Protocol
# CELERY_RESULT_DBURI = ""
CELERY_TIMEZONE = "Asia/Kolkata"
#CELERY_RESULT_BACKEND='djcelery.backends.cache:CacheBackend'
CELERY_RESULT_BACKEND = 'djcelery.backends.database:DatabaseBackend'
CELERY_IMPORTS = ("tasks", )
CELERY_RESULT_PERSISTENT = True #If set to True, result messages will be persistent. This means the messages will not be lost after a broker restart. The default is for the results to be transient.
CELERY_TASK_RESULT_EXPIRES = None #Never delete the SUCCESSFUL tasks from the database. http://docs.celeryproject.org/en/latest/configuration.html#celery-task-result-expires
# CELERY_RESULT_BACKEND = 'cache+memcached://127.0.0.1:11211/'
# CELERY_CACHE_BACKEND = 'memory'
#http://www.hiddentao.com/archives/2012/01/27/processing-long-running-django-tasks-using-celery-rabbitmq-supervisord-monit/
'''
Celery configurations ends
'''
最佳答案
如果您不想配置数据库,因为您正在使用 mongoengine,那么请从您的设置中完全删除 DATABASES,或者将其更改为空字典。
DATABASES = {}
如果您确实在DATABASES 字典中包含任何项目,那么它们必须包含ENGINE。 ,否则您将收到 ImproperlyConfigured 错误。
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
...
},
}
关于Django1.8 和 Mongoclient settings.DATABASES 配置不当。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44948303/
我有一个在Linux服务器上运行的ruby脚本。它不使用rails或任何东西。它基本上是一个命令行ruby脚本,可以像这样传递参数:./ruby_script.rbarg1arg2如何将参数抽象到配置文件(例如yaml文件或其他文件)中?您能否举例说明如何做到这一点?提前谢谢你。 最佳答案 首先,您可以运行一个写入YAML配置文件的独立脚本:require"yaml"File.write("path_to_yaml_file",[arg1,arg2].to_yaml)然后,在您的应用中阅读它:require"yaml"arg
我已经在Sinatra上创建了应用程序,它代表了一个简单的API。我想在生产和开发上进行部署。我想在部署时选择,是开发还是生产,一些方法的逻辑应该改变,这取决于部署类型。是否有任何想法,如何完成以及解决此问题的一些示例。例子:我有代码get'/api/test'doreturn"Itisdev"end但是在部署到生产环境之后我想在运行/api/test之后看到ItisPROD如何实现? 最佳答案 根据SinatraDocumentation:EnvironmentscanbesetthroughtheRACK_ENVenvironm
之前在培训新生的时候,windows环境下配置opencv环境一直教的都是网上主流的vsstudio配置属性表,但是这个似乎对新生来说难度略高(虽然个人觉得完全是他们自己的问题),加之暑假之后对cmake实在是爱不释手,且这样配置确实十分简单(其实都不需要配置),故斗胆妄言vscode下配置CV之法。其实极为简单,图比较多所以很长。如果你看此文还配不好,你应该思考一下是不是自己的问题。闲话少说,直接开始。0.CMkae简介有的人到大二了都不知道cmake是什么,我不说是谁。CMake是一个开源免费并且跨平台的构建工具,可以用简单的语句来描述所有平台的编译过程。它能够根据当前所在平台输出对应的m
注意:本文主要掌握DCN自研无线产品的基本配置方法和注意事项,能够进行一般的项目实施、调试与运维AP基本配置命令AP登录用户名和密码均为:adminAP默认IP地址为:192.168.1.10AP默认情况下DHCP开启AP静态地址配置:setmanagementstatic-ip192.168.10.1AP开启/关闭DHCP功能:setmanagementdhcp-statusup/downAP设置默认网关:setstatic-ip-routegeteway192.168.10.254查看AP基本信息:getsystemgetmanagementgetmanaged-apgetrouteAP配
1.1.1 YARN的介绍 为克服Hadoop1.0中HDFS和MapReduce存在的各种问题⽽提出的,针对Hadoop1.0中的MapReduce在扩展性和多框架⽀持⽅⾯的不⾜,提出了全新的资源管理框架YARN. ApacheYARN(YetanotherResourceNegotiator的缩写)是Hadoop集群的资源管理系统,负责为计算程序提供服务器计算资源,相当于⼀个分布式的操作系统平台,⽽MapReduce等计算程序则相当于运⾏于操作系统之上的应⽤程序。 YARN被引⼊Hadoop2,最初是为了改善MapReduce的实现,但是因为具有⾜够的通⽤性,同样可以⽀持其他的分布式计算模
我是ruby的新手,正在配置IRB。我喜欢pretty-print(需要'pp'),但总是输入pp来漂亮地打印它似乎很麻烦。我想做的是默认情况下让它漂亮地打印出来,所以如果我有一个var,比如说,'myvar',然后键入myvar,它会自动调用pretty_inspect而不是常规检查。我从哪里开始?理想情况下,我将能够向我的.irbrc文件添加一个自动调用的方法。有什么想法吗?谢谢! 最佳答案 irb中默认pretty-print对象正是hirb被迫去做。Theseposts解释hirb如何将几乎所有内容转换为ascii表。虽
我想在IRB中浏览文件系统并让提示更改以反射(reflect)当前工作目录,但我不知道如何在每个命令后进行提示更新。最终,我想在日常工作中更多地使用IRB,让bash溜走。我在我的.irbrc中试过这个:require'fileutils'includeFileUtilsIRB.conf[:PROMPT][:CUSTOM]={:PROMPT_N=>"\e[1m:\e[m",:PROMPT_I=>"\e[1m#{pwd}>\e[m",:PROMPT_S=>"FOO",:PROMPT_C=>"\e[1m#{pwd}>\e[m",:RETURN=>""}IRB.conf[:PROMPT_MO
我正在使用Ruby/Mechanize编写一个“自动填写表格”应用程序。它几乎可以工作。我可以使用精彩CharlesWeb代理以查看服务器和我的Firefox浏览器之间的交换。现在我想使用Charles查看服务器和我的应用程序之间的交换。Charles在端口8888上代理。假设服务器位于https://my.host.com。.一件不起作用的事情是:@agent||=Mechanize.newdo|agent|agent.set_proxy("my.host.com",8888)end这会导致Net::HTTP::Persistent::Error:...lib/net/http/pe
我正在尝试使用gsub方法将电子邮件中的所有字母数字字符替换为“#”字符,但Ruby在“@”字符之前插入了一个反斜杠。例如:"john@doe.com".gsub(/[a-z0-9]/,"#")返回"###\#@###.###"而不是"####@###.###"。 最佳答案 它按预期返回"####@###.###",尝试:puts"john@doe.com".gsub(/[a-z0-9]/,"#")您在IRB/Pry中看到的是防止#@被解释为字符串插值。另请参阅下面@Stefan的非常有值(value)的评论。
如果特定语言环境中缺少翻译,如何配置i18n以使用en语言环境翻译?当前已插入翻译缺失消息。我正在使用RoR3.1。 最佳答案 找到相似的question这里是答案:#application.rb#railswillfallbacktoconfig.i18n.default_localetranslationconfig.i18n.fallbacks=true#railswillfallbacktoen,nomatterwhatissetasconfig.i18n.default_localeconfig.i18n.fallback