Skip to content

Commit

Permalink
last
Browse files Browse the repository at this point in the history
  • Loading branch information
sam committed Mar 1, 2019
1 parent 9642d1c commit bd6f118
Show file tree
Hide file tree
Showing 55 changed files with 1,948 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,10 @@ venv.bak/

# mypy
.mypy_cache/
.idea
medias/
db.sqlite3
migrations/
.qiniu_pythonsdk_hostscache.json
./logs/*.log

7 changes: 7 additions & 0 deletions Django_Friends/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import pymysql
pymysql.install_as_MySQLdb()

from libs.orm import patch_model

patch_model()

36 changes: 36 additions & 0 deletions Django_Friends/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
# @Time : 19-2-13 下午7:43
# @Author : SamSa
# @Email : [email protected]
# @File : config.py
# @statement:项目以及第三方配置

# 云之讯短信平台配置
YZX_SMS_API = 'https://open.ucpaas.com/ol/sms/sendsms'
YZX_SMS_PARAMS = {
"sid": 'a9f0c6e073539cb1946b0ff901816aed',
"token": 'e5831a53e875a8fb73371caa146ed182',
"appid": '33eb8c92d2e4471e9d64c77e99a7201a',
"templateid": "430588",
"param": None,
"mobile": None,
}


# 七牛云配置
QN_ACCESS_KEY = 'j4mpIn_WwSnM8EfYGGXqmq33b-GsYqdGflLOBKRL'
QN_SECRET_KEY = 'fUzrs4GqcU1DVgE3mLCA8RuE4Z5Gyv5tVFcnSqfF'
QN_HOST = 'http://pmy2ozqbl.bkt.clouddn.com'
QN_BUCKET = 'tantan'

# 反悔次数

BACK_TIME = 3

# 滑动积分
SWIPE_SCORE = {
'like': 5,
'superlike': 7,
'dislike': -5,
}

41 changes: 41 additions & 0 deletions Django_Friends/gunicorn_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
# @Time : 19-2-21 上午11:51
# @Author : SamSa
# @Email : [email protected]
# @File : gunicorn_config.py
# @statement:gunicorn配置项

from multiprocessing import cpu_count

"""
初始化数据库,注意初始化位置,在项目加载之前初始化,
否则抛出异常: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
"""
# import pymysql
#
# pymysql.install_as_MySQLdb()


bind = ['127.0.0.1:9000'] # 线上环境不会开启在公网 IP 下,一般使用内网 IP
daemon = True # 是否开启守护进程模式
# daemon = False # 是否开启守护进程模式
pidfile = 'logs/gunicorn.pid'

workers = cpu_count() * 2 # 工作进程数量
worker_class = 'gevent' # 指定一个异步处理的库
worker_connections = 65535

keepalive = 60 # 服务器保持链接时间,避免频繁的tcp连接
timeout = 30
graceful_timeout = 10
forwarded_allow_ips = '*'

# 日志处理
capture_output = True
loglevel = 'info'
errorlog = 'logs/gunicorn_error.log'




221 changes: 221 additions & 0 deletions Django_Friends/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
"""
Django settings for Django_Friends project.
Generated by 'django-admin startproject' using Django 1.11.7.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
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.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'j7s^9h92wkgfh#72hd%+y6o@l!=8^1f&kx+n5!phoqyx7k(!=q'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
INTERNAL_IPS = ('127.0.0.1')
ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

'debug_toolbar',

'user',
'social',
'vip',
]

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

# debug
'debug_toolbar.middleware.DebugToolbarMiddleware',

'common.middleware.AuthMiddleWare',
'common.middleware.ErrorMiddleWare',
]

ROOT_URLCONF = 'Django_Friends.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 = 'Django_Friends.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE':'django.db.backends.mysql',
'NAME':'tantan',
'USER': 'root',
'PASSWORD': '123456',
'HOST': '127.0.0.1',
'PORT': 3306,
}
}


# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

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


# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True
USE_TZ = False


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = '/static/'

# 缓存


CACHE ={
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': 'redis://127.0.0.1:6379/0',
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
}
}
}

# 文件上传路径

MEDIA_ROOT = 'medias'


# 日志配置
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
# 格式配置
'formatters': {
'simple': {
'format': '%(asctime)s %(module)s.%(funcName)s: %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S',
},
'verbose': {
'format': ('%(asctime)s %(levelname)s [%(process)d-%(threadName)s] '
'%(module)s.%(funcName)s line %(lineno)d: %(message)s'),
'datefmt': '%Y-%m-%d %H:%M:%S',
}
},
# Handler 配置
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'level': 'DEBUG' if DEBUG else 'WARNING'
},
'info': {
'class': 'logging.handlers.TimedRotatingFileHandler',
'filename': f'{BASE_DIR}/logs/info.log', # 日志保存路径
'when': 'D', # 每天切割日志
'backupCount': 5, # 日志保留 30 天
'formatter': 'simple',
'level': 'INFO',
},
'error': {
'class': 'logging.handlers.TimedRotatingFileHandler',
'filename': f'{BASE_DIR}/logs/error.log', # 日志保存路径
'when': 'W0', # 每周一切割日志
'backupCount': 4, # 日志保留 4 周
'formatter': 'verbose',
'level': 'WARNING',
}
},
# Logger 配置
'loggers': {
'django': {
'handlers': ['console'],
},
'inf': {
'handlers': ['info'],
'propagate': True,
'level': 'INFO',
},
'err': {
'handlers': ['error'],
'propagate': True,
'level': 'WARNING',
}
}
}

# redis配置
REDIS = {
'host': '127.0.0.1',
'port': 6379,
'db': 1,
}


35 changes: 35 additions & 0 deletions Django_Friends/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Django_TanTan URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.contrib import admin

from Django_Friends import settings

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^user/', include('user.urls', namespace='user')),
url(r'^social/', include('social.urls', namespace='social')),

url(r'^vip/', include('vip.urls')),

]


if settings.DEBUG:
import debug_toolbar
urlpatterns = [
url(r'^__debug__/', include(debug_toolbar.urls))
] + urlpatterns
16 changes: 16 additions & 0 deletions Django_Friends/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for Django_TanTan project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Django_TanTan.settings")

application = get_wsgi_application()
6 changes: 6 additions & 0 deletions common/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# @Time : 19-2-13 下午8:14
# @Author : SamSa
# @Email : [email protected]
# @File : script.py.py
# @statement:
Loading

0 comments on commit bd6f118

Please sign in to comment.