settings.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. """
  2. Django settings for WeiBoCrawler project.
  3. Generated by 'django-admin startproject' using Django 2.0.13.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/2.0/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/2.0/ref/settings/
  8. """
  9. import os
  10. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  11. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  12. # Quick-start development settings - unsuitable for production
  13. # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
  14. # SECURITY WARNING: keep the secret key used in production secret!
  15. SECRET_KEY = '%hx+uaex_$6q@db4tv=ki^5%4d6g=m=h-8g3_ypwrxe13(!p_-'
  16. # SECURITY WARNING: don't run with debug turned on in production!
  17. DEBUG = True
  18. ALLOWED_HOSTS = []
  19. # Application definition
  20. INSTALLED_APPS = [
  21. 'django.contrib.admin',
  22. 'django.contrib.auth',
  23. 'django.contrib.contenttypes',
  24. 'django.contrib.sessions',
  25. 'django.contrib.messages',
  26. 'django.contrib.staticfiles',
  27. 'rest_framework',
  28. 'CrawKeywords',
  29. 'Profile',
  30. # The following apps are required:
  31. 'django.contrib.sites',
  32. 'allauth',
  33. 'allauth.account',
  34. 'allauth.socialaccount',
  35. 'corsheaders',
  36. ]
  37. MIDDLEWARE = [
  38. 'django.middleware.security.SecurityMiddleware',
  39. 'django.contrib.sessions.middleware.SessionMiddleware',
  40. 'django.middleware.common.CommonMiddleware',
  41. 'django.middleware.csrf.CsrfViewMiddleware',
  42. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  43. 'django.contrib.messages.middleware.MessageMiddleware',
  44. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  45. 'corsheaders.middleware.CorsMiddleware',
  46. ]
  47. ROOT_URLCONF = 'WeiBoCrawler.urls'
  48. TEMPLATES = [
  49. {
  50. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  51. 'DIRS': [os.path.join(BASE_DIR, 'templates')],
  52. 'APP_DIRS': True,
  53. 'OPTIONS': {
  54. 'context_processors': [
  55. 'django.template.context_processors.debug',
  56. 'django.template.context_processors.request',
  57. 'django.contrib.auth.context_processors.auth',
  58. 'django.contrib.messages.context_processors.messages',
  59. 'django.template.context_processors.request',
  60. ],
  61. },
  62. },
  63. ]
  64. # django-allauth基本配置
  65. ACCOUNT_AUTHENTICATION_METHOD = 'username_email' # 可以使用用户名或邮箱登录
  66. ACCOUNT_EMAIL_REQUIRED = True # 必须设置电子邮箱
  67. LOGIN_REDIRECT_URL = '/' # 登录成功后的跳转地址
  68. ACCOUNT_LOGOUT_REDIRECT_URL = '/' # 退出登录后跳转链接
  69. # 发送邮件配置项
  70. # SMTP服务器地址
  71. EMAIL_HOST = 'smtp.exmail.qq.com'
  72. # 端口
  73. EMAIL_PORT = 25
  74. # 发送邮件的邮箱
  75. EMAIL_HOST_USER = 'shellmiao@shellmiao.com'
  76. # 在邮箱中设置的客户端授权密码
  77. EMAIL_HOST_PASSWORD = 'KU3awdLM2MnDqdbM'
  78. EMAIL_USE_TLS = True
  79. # 收件人看到的发件人
  80. EMAIL_FROM = 'shellmiao<shellmiao@shellmiao.com>'
  81. # 报错此项必须加上
  82. DEFAULT_FROM_EMAIL = 'shellmiao@shellmiao.com'
  83. AUTHENTICATION_BACKENDS = [
  84. # Needed to login by username in Django admin, regardless of `allauth`
  85. 'django.contrib.auth.backends.ModelBackend',
  86. # `allauth` specific authentication methods, such as login by e-mail
  87. 'allauth.account.auth_backends.AuthenticationBackend',
  88. ]
  89. # 注册中邮件验证方法
  90. ACCOUNT_EMAIL_VERIFICATION = "mandatory"
  91. # 邮件发送后的冷却时间(以秒为单位)
  92. ACCOUNT_EMAIL_CONFIRMATION_COOLDOWN = 180
  93. # 登录尝试失败的次数
  94. ACCOUNT_LOGIN_ATTEMPTS_LIMIT = 5
  95. # 从上次失败的登录尝试,用户被禁止尝试登录的持续时间
  96. ACCOUNT_LOGIN_ATTEMPTS_TIMEOUT = 300
  97. # 电子邮件地址的唯一性
  98. ACCOUNT_UNIQUE_EMAIL = True
  99. WSGI_APPLICATION = 'WeiBoCrawler.wsgi.application'
  100. # Database
  101. # https://docs.djangoproject.com/en/2.0/ref/settings/#databases
  102. DATABASES = {
  103. 'default': {
  104. 'ENGINE': 'django.db.backends.mysql',
  105. 'NAME': 'WeiBoCrawler',
  106. 'USER': 'crawler',
  107. 'PASSWORD': 'Crawler2020520very+',
  108. 'HOST': '42.192.54.32',
  109. 'PORT': '3306',
  110. }
  111. }
  112. # Password validation
  113. # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
  114. AUTH_PASSWORD_VALIDATORS = [
  115. {
  116. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  117. },
  118. {
  119. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  120. },
  121. {
  122. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  123. },
  124. {
  125. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  126. },
  127. ]
  128. # allauth
  129. SITE_ID = 1
  130. # Internationalization
  131. # https://docs.djangoproject.com/en/2.0/topics/i18n/
  132. LANGUAGE_CODE = 'en-us'
  133. TIME_ZONE = 'UTC'
  134. USE_I18N = True
  135. USE_L10N = True
  136. USE_TZ = True
  137. # Static files (CSS, JavaScript, Images)
  138. # https://docs.djangoproject.com/en/2.0/howto/static-files/
  139. STATIC_URL = '/static/'
  140. REST_FRAMEWORK = {
  141. 'DEFAULT_RENDERER_CLASSES': (
  142. 'rest_framework.renderers.BrowsableAPIRenderer',
  143. 'rest_framework.renderers.JSONRenderer',
  144. )
  145. }
  146. # 凡是出现在白名单中的域名,都可以访问后端接口
  147. # 添加 django-cors-headers 的白名单, 使白名单中的 host 可以进行跨域请求
  148. # CORS_ORIGIN_WHITELIST = (
  149. # # 白名单:
  150. # "127.0.0.1:3000"
  151. # )
  152. CORS_ORIGIN_ALLOW_ALL = True # 所有人
  153. # 允许白名单中的 host 跨域请求时携带 cookie
  154. CORS_ALLOW_CREDENTIALS = True