连接mongodb

时间:2017-02-22 08:41:45

标签: python django mongodb python-3.6

我需要知道如何将 #include <stdio.h> int main() { float gpa; float numberGrade = 0; float sum = 0; int i, numCourse; char letterGrade, modifier; printf("Enter the number of course: "); scanf("%d", &numCourse); for (i = 0; i < numCourse; i++) { printf("What grade did you earn?\n"); printf("Enter A, B, C, D, or F: "); scanf(" %c", &letterGrade); switch (letterGrade) { case 'A': numberGrade = 4.0; break; case 'B': numberGrade = 3.0; break; case 'C': numberGrade = 2.0; break; case 'D': numberGrade = 1.0; break; default: numberGrade = 0.0; break; } printf( "Enter modifier - for letter grades A-, etc. + for letter grades B+, etc. , and _ for letter grades A, B, etc.: "); scanf(" %c", &modifier); if (modifier == '-') numberGrade = numberGrade - 0.3; else if (modifier == '+') numberGrade = numberGrade + 0.3; sum = sum + numberGrade; } gpa = sum / numCourse; printf("The final gpa is %.2f.\n", gpa); return 0; } 连接为主数据库。

请指导我连接数据库

1 个答案:

答案 0 :(得分:-1)

安装mongoengine app

settings.py文件中,您可以添加以下内容..

'mongoengine.django.mongo_auth',

中添加INSTALLED_APPS

为身份验证

定义mongodb用户模型

AUTH_USER_MODEL =&#39; mongo_auth.MongoUser&#39;

会话存储设置

SESSION_ENGINE =&#39; mongoengine.django.sessions&#39;

SESSION_SERIALIZER =&#39; mongoengine.django.sessions.BSONSerializer&#39;

数据库设置如下

from mongoengine import connect
connect('database_name', host='***.***.**.**', port=27017)

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