a90b24be by Gruel

project init

0 parents
1 # Byte-compiled / optimized / DLL files
2 *.[oa]
3 *~
4 *.py[cod]
5 *$py.class
6 **/*.py[cod]
7
8 # Log
9 log/*
10 logs/
11 *.log
12 *log
13
14 # Diff
15 *.diff
16
17 #Hidden
18 .*
19 !.gitignore
20 !.style.yapf
21
22 #测试db
23 test.db
24 sftp-config.json
25
26 #virtual env:
27 *env/*
28
29 *.sqlite3
30 conf/*
31
32 # 脚本
33 src/*.sh
...\ No newline at end of file ...\ No newline at end of file
1 certifi==2016.2.28
2 Django==2.1
3 pytz==2020.1
4 # simple-config @ http://gitlab.situdata.com/zhouweiqi/simple_config/repository/archive.tar.gz?ref=master
1 http://gitlab.situdata.com/zhouweiqi/simple_config/repository/archive.tar.gz?ref=master
...\ No newline at end of file ...\ No newline at end of file
File mode changed
1 """biz_logic URL Configuration
2
3 The `urlpatterns` list routes URLs to views. For more information please see:
4 https://docs.djangoproject.com/en/2.1/topics/http/urls/
5 Examples:
6 Function views
7 1. Add an import: from my_app import views
8 2. Add a URL to urlpatterns: path('', views.home, name='home')
9 Class-based views
10 1. Add an import: from other_app.views import Home
11 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12 Including another URLconf
13 1. Import the include() function: from django.urls import include, path
14 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15 """
16 from django.contrib import admin
17 from django.urls import path
18
19 urlpatterns = [
20 path('admin/', admin.site.urls),
21 ]
1 #!/usr/bin/env python
2 import os
3 import sys
4
5 if __name__ == '__main__':
6 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
7 try:
8 from django.core.management import execute_from_command_line
9 except ImportError as exc:
10 raise ImportError(
11 "Couldn't import Django. Are you sure it's installed and "
12 "available on your PYTHONPATH environment variable? Did you "
13 "forget to activate a virtual environment?"
14 ) from exc
15 execute_from_command_line(sys.argv)
1 """
2 Django settings for biz_logic project.
3
4 Generated by 'django-admin startproject' using Django 2.1.
5
6 For more information on this file, see
7 https://docs.djangoproject.com/en/2.1/topics/settings/
8
9 For the full list of settings and their values, see
10 https://docs.djangoproject.com/en/2.1/ref/settings/
11 """
12
13 import os
14 from . import conf
15
16 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
17 BASE_DIR = conf.BASE_DIR
18
19
20 # Quick-start development settings - unsuitable for production
21 # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
22
23 # SECURITY WARNING: keep the secret key used in production secret!
24 SECRET_KEY = 'd!l6b6vz6s5dm9ysdfc-y1n*q3vukr-cix9rntx&5me$-)@wli'
25
26 # SECURITY WARNING: don't run with debug turned on in production!
27 DEBUG = conf.DEBUG
28
29 ALLOWED_HOSTS = conf.ALLOWED_HOSTS
30
31
32 # Application definition
33
34 INSTALLED_APPS = [
35 'django.contrib.admin',
36 'django.contrib.auth',
37 'django.contrib.contenttypes',
38 'django.contrib.sessions',
39 'django.contrib.messages',
40 'django.contrib.staticfiles',
41 ]
42
43 MIDDLEWARE = [
44 'django.middleware.security.SecurityMiddleware',
45 'django.contrib.sessions.middleware.SessionMiddleware',
46 'django.middleware.common.CommonMiddleware',
47 'django.middleware.csrf.CsrfViewMiddleware',
48 'django.contrib.auth.middleware.AuthenticationMiddleware',
49 'django.contrib.messages.middleware.MessageMiddleware',
50 'django.middleware.clickjacking.XFrameOptionsMiddleware',
51 ]
52
53 ROOT_URLCONF = 'apps.urls'
54
55 TEMPLATES = [
56 {
57 'BACKEND': 'django.template.backends.django.DjangoTemplates',
58 'DIRS': [],
59 'APP_DIRS': True,
60 'OPTIONS': {
61 'context_processors': [
62 'django.template.context_processors.debug',
63 'django.template.context_processors.request',
64 'django.contrib.auth.context_processors.auth',
65 'django.contrib.messages.context_processors.messages',
66 ],
67 },
68 },
69 ]
70
71 WSGI_APPLICATION = 'wsgi.application'
72
73
74 # Database
75 # https://docs.djangoproject.com/en/2.1/ref/settings/#databases
76
77 DATABASES = {
78 'default': {
79 'ENGINE': 'django.db.backends.sqlite3',
80 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
81 }
82 }
83
84
85 # Password validation
86 # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
87
88 AUTH_PASSWORD_VALIDATORS = [
89 {
90 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
91 },
92 {
93 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
94 },
95 {
96 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
97 },
98 {
99 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
100 },
101 ]
102
103
104 # Internationalization
105 # https://docs.djangoproject.com/en/2.1/topics/i18n/
106
107 LANGUAGE_CODE = 'zh-hans'
108
109 TIME_ZONE = 'Asia/Shanghai'
110
111 USE_I18N = True
112
113 USE_L10N = True
114
115 USE_TZ = False
116
117
118 # Static files (CSS, JavaScript, Images)
119 # https://docs.djangoproject.com/en/2.1/howto/static-files/
120
121 STATIC_URL = '/static/'
1 """
2 配置分为两部分:
3 1. 通用配置(common), 如token过期时间,不能发在源代码中, 存放在src/settings下,
4 2. 私密配置(secret),如帐号、密码, 不能放在源代码中
5 """
6 import os
7 import sys
8
9 from django.core.management.color import color_style
10
11 from simple_config import Config, ConfigAttribute, converter
12
13 from . import _default_config
14
15 _SERVER_TYPE_LST = ['DEV', 'SIT', 'PRD']
16
17
18 def service_is_online(server_type):
19 return server_type == 'PRD'
20
21
22 class ProjectConfig(Config):
23 DEBUG = ConfigAttribute('DEBUG', get_converter=converter.boolean)
24 SERVICE_IS_ONLINE = ConfigAttribute(
25 'SERVER_TYPE', get_converter=service_is_online)
26 ALLOWED_HOSTS = ConfigAttribute(
27 'ALLOWED_HOSTS', get_converter=converter.Csv())
28 # ETCD_PORT = ConfigAttribute('ETCD_PORT', get_converter=int)
29
30 def load_config(self):
31 # 加载默认配置
32 self.from_object(_default_config)
33 self.load_secret_config()
34 self.load_common_config()
35
36 def load_common_config(self):
37 """加载配置文件
38 """
39 self.from_env_var('SERVER_TYPE')
40 assert self.SERVER_TYPE in _SERVER_TYPE_LST
41 config_file = self.get_common_config_filename(self.COMMON_CONF_DIR,
42 self.SERVER_TYPE)
43 if self.SERVER_TYPE == 'DEV' and not os.path.exists(config_file):
44 msg = '[SERVER_TYPE: %s] config_file: %s does not exist' % (
45 self.SERVER_TYPE, config_file)
46 config_file = self.get_common_config_filename(
47 self.COMMON_CONF_DIR, 'SIT')
48 msg = '%s, try to use %s as alternative\n' % (msg, config_file)
49 style = color_style()
50 sys.stdout.write(style.NOTICE(msg))
51 self.from_ini(config_file)
52
53 def load_secret_config(self):
54 """加载私密配置
55 """
56 self.from_ini(self.SECRET_CONF_FILE)
57
58 @staticmethod
59 def get_common_config_filename(conf_dir, server_type):
60 return os.path.join(conf_dir, '%s.ini' % server_type.lower())
61
62
63 config = ProjectConfig()
64 config.load_config()
65
66 sys.modules[__name__] = config
1 import os
2
3 # 路径相关
4 BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
5 COMMON_CONF_DIR = os.path.dirname(os.path.abspath(__file__))
6 SECRET_CONF_DIR = os.path.join(os.path.dirname(BASE_DIR), 'conf')
7 SECRET_CONF_FILE = os.path.join(SECRET_CONF_DIR, 'secret.ini')
8 LOGGING_CONFIG_FILE = os.path.join(COMMON_CONF_DIR, 'logging.conf')
9
10 # 文件存放根目录
11 LOG_DIR = os.path.join(os.path.dirname(BASE_DIR), 'logs')
12
13 # WEB相关
14 ALLOWED_HOSTS = '*'
15
16 # jwt过期时间
17 # JWT_EXPIRATION_DAYS = 1
1 [settings]
2 DEBUG = False
...\ No newline at end of file ...\ No newline at end of file
1 [settings]
2 DEBUG = True
...\ No newline at end of file ...\ No newline at end of file
1 [settings]
2 DEBUG = False
...\ No newline at end of file ...\ No newline at end of file
1 """
2 WSGI config for biz_logic project.
3
4 It exposes the WSGI callable as a module-level variable named ``application``.
5
6 For more information on this file, see
7 https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/
8 """
9
10 import os
11
12 from django.core.wsgi import get_wsgi_application
13
14 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
15
16 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!