2016-09-21 48 views
2

我是python,django和mongoDB世界的新手。我設置的Django項目(VIRTUALENV,Python3,Django的== 1.10.1的MongoDB),並安裝了一些基本的程序包要求:如何在Django Framework和Python3中使用MongoDB

Django==1.10.1 
django-mongodb-engine==0.6.0 
djangotoolbox==1.8.0 
mongoengine==0.9.0 
pymongo==3.3.0 

但是當我試圖用python3 manage.py syncdb來執行syncdb,那麼它顯示

~/virtenv/lib/python3.5/site-packages/django_mongodb_engine/base.py", line 272 
    raise ImproperlyConfigured, exc_info[1], exc_info[2] 
          ^
SyntaxError: invalid syntax 

Settings.py

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


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', 
] 

MIDDLEWARE = [ 
    'django.middleware.security.SecurityMiddleware', 
    '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 = 'fvp_amu.urls' 

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [], 
     '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', 
      ], 
     }, 
    }, 
] 

WSGI_APPLICATION = 'fvp_amu.wsgi.application' 


# Database 

DATABASES = { 
    'default' : { 
     'ENGINE' : '', 
     'NAME' : 'fvp_amu' 
     } 
    } 

# Password validation 

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', 
    }, 
] 

STATIC_URL = '/static/' 
+0

請添加您的settings.py。 – Windsooon

+0

我已經添加了setting.py @Windso –

回答

1

從文檔django-mongodb-engine

DATABASES = { 
    'default' : { 
     'ENGINE' : 'django_mongodb_engine', 
     'NAME' : 'my_database' 
    } 
} 
+0

他希望爲MongoDB完成你爲PostGRES添加指令 – harshil9968

+0

抱歉,我的錯誤。 – Windsooon

+0

@Windsooon它不起作用 –

相關問題