a90b24be by Gruel

project init

0 parents
# Byte-compiled / optimized / DLL files
*.[oa]
*~
*.py[cod]
*$py.class
**/*.py[cod]
# Log
log/*
logs/
*.log
*log
# Diff
*.diff
#Hidden
.*
!.gitignore
!.style.yapf
#测试db
test.db
sftp-config.json
#virtual env:
*env/*
*.sqlite3
conf/*
# 脚本
src/*.sh
\ No newline at end of file
certifi==2016.2.28
Django==2.1
pytz==2020.1
# simple-config @ http://gitlab.situdata.com/zhouweiqi/simple_config/repository/archive.tar.gz?ref=master
http://gitlab.situdata.com/zhouweiqi/simple_config/repository/archive.tar.gz?ref=master
\ No newline at end of file
File mode changed
"""biz_logic URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
#!/usr/bin/env python
import os
import sys
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
"""
Django settings for biz_logic project.
Generated by 'django-admin startproject' using Django 2.1.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import os
from . import conf
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = conf.BASE_DIR
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'd!l6b6vz6s5dm9ysdfc-y1n*q3vukr-cix9rntx&5me$-)@wli'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = conf.DEBUG
ALLOWED_HOSTS = conf.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 = 'apps.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 = 'wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.1/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/2.1/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/2.1/howto/static-files/
STATIC_URL = '/static/'
"""
配置分为两部分:
1. 通用配置(common), 如token过期时间,不能发在源代码中, 存放在src/settings下,
2. 私密配置(secret),如帐号、密码, 不能放在源代码中
"""
import os
import sys
from django.core.management.color import color_style
from simple_config import Config, ConfigAttribute, converter
from . import _default_config
_SERVER_TYPE_LST = ['DEV', 'SIT', 'PRD']
def service_is_online(server_type):
return server_type == 'PRD'
class ProjectConfig(Config):
DEBUG = ConfigAttribute('DEBUG', get_converter=converter.boolean)
SERVICE_IS_ONLINE = ConfigAttribute(
'SERVER_TYPE', get_converter=service_is_online)
ALLOWED_HOSTS = ConfigAttribute(
'ALLOWED_HOSTS', get_converter=converter.Csv())
# ETCD_PORT = ConfigAttribute('ETCD_PORT', get_converter=int)
def load_config(self):
# 加载默认配置
self.from_object(_default_config)
self.load_secret_config()
self.load_common_config()
def load_common_config(self):
"""加载配置文件
"""
self.from_env_var('SERVER_TYPE')
assert self.SERVER_TYPE in _SERVER_TYPE_LST
config_file = self.get_common_config_filename(self.COMMON_CONF_DIR,
self.SERVER_TYPE)
if self.SERVER_TYPE == 'DEV' and not os.path.exists(config_file):
msg = '[SERVER_TYPE: %s] config_file: %s does not exist' % (
self.SERVER_TYPE, config_file)
config_file = self.get_common_config_filename(
self.COMMON_CONF_DIR, 'SIT')
msg = '%s, try to use %s as alternative\n' % (msg, config_file)
style = color_style()
sys.stdout.write(style.NOTICE(msg))
self.from_ini(config_file)
def load_secret_config(self):
"""加载私密配置
"""
self.from_ini(self.SECRET_CONF_FILE)
@staticmethod
def get_common_config_filename(conf_dir, server_type):
return os.path.join(conf_dir, '%s.ini' % server_type.lower())
config = ProjectConfig()
config.load_config()
sys.modules[__name__] = config
import os
# 路径相关
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
COMMON_CONF_DIR = os.path.dirname(os.path.abspath(__file__))
SECRET_CONF_DIR = os.path.join(os.path.dirname(BASE_DIR), 'conf')
SECRET_CONF_FILE = os.path.join(SECRET_CONF_DIR, 'secret.ini')
LOGGING_CONFIG_FILE = os.path.join(COMMON_CONF_DIR, 'logging.conf')
# 文件存放根目录
LOG_DIR = os.path.join(os.path.dirname(BASE_DIR), 'logs')
# WEB相关
ALLOWED_HOSTS = '*'
# jwt过期时间
# JWT_EXPIRATION_DAYS = 1
[settings]
DEBUG = False
\ No newline at end of file
[settings]
DEBUG = True
\ No newline at end of file
[settings]
DEBUG = False
\ No newline at end of file
"""
WSGI config for biz_logic 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/2.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
application = get_wsgi_application()
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!