Production
Development 发展
Production 开发
Prod 产品
source 来源
assing to order 服从命令,排序
does 做
outstanding 未解决
actual 实际的
available 可获得的
process node 工艺节点
widgets 小器件
record 记录
Account 账户
complete 完成
error
1. 描述: django项目启动使用了environ.db()读取报错
DATABASES = {"default": env.db("DATABASE_URL")}
USE_DOCKER=yes
IPYTHONDIR=/app/.ipython
FGR_MIDDLEWARE_ENDPOINT=https://efmiddlewaredev.tslj.com.cn/middleware/api
FGR_MIDDLEWARE_USERNAME=FGRAPI
FGR_MIDDLEWARE_PASSWORD=123456
FGR_TIMEOUT=30
DJANGO_HOST=http://127.0.0.1:8000
DJANGO_STATIC_ORDER_IMG=False
POSTGRES_HOST=127.0.0.1
POSTGRES_PORT=5437
POSTGRES_DB=tsl_backend
POSTGRES_USER=debug
POSTGRES_PASSWORD=debug
DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
步骤复现
vscode终端运行
python .\manage.py runserver
Traceback (most recent call last):
File "C:\Users\atang\Desktop\github\hkpc-tsl-system-main\tsl_backend\manage.py", line 31, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
utility.execute()
File "C:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\django\core\management\__init__.py", line 382, in execute
settings.INSTALLED_APPS
File "C:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\django\conf\__init__.py", line 102, in __getattr__
self._setup(name)
File "C:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\django\conf\__init__.py", line 89, in _setup
self._wrapped = Settings(settings_module)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\django\conf\__init__.py", line 217, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\atang\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\atang\Desktop\github\hkpc-tsl-system-main\tsl_backend\config\settings\local.py", line 1, in <module>
from .base import * # noqa
^^^^^^^^^^^^^^^^^^^
File "C:\Users\atang\Desktop\github\hkpc-tsl-system-main\tsl_backend\config\settings\base.py", line 51, in <module>
DATABASES = {"default": env.db("DATABASE_URL")}
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\environ\environ.py", line 310, in db_url
return self.db_url_config(
^^^^^^^^^^^^^^^^^^^
File "C:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\environ\environ.py", line 569, in db_url_config
port = url.port
^^^^^^^^
File "C:\Users\atang\AppData\Local\Programs\Python\Python311\Lib\urllib\parse.py", line 173, in port
raise ValueError(f"Port could not be cast to integer value as {port!r}")
ValueError: Port could not be cast to integer value as '${POSTGRES_PORT}'
解决
使用vscode的调试模式就能正常运行
2. drf_spectacular自动生成接口文档异常
THIRD_PARTY_APPS = [
"crispy_forms",
"crispy_bootstrap5",
"allauth",
"allauth.account",
"allauth.socialaccount",
"rest_framework",
"rest_framework.authtoken",
"corsheaders",
"drf_spectacular",
"drf_spectacular_sidecar",
"rest_framework_simplejwt",
'rest_framework_simplejwt.token_blacklist',
]
SPECTACULAR_SETTINGS = {
# "TITLE": "HKPC TSL e-Order System API",
# "DESCRIPTION": "Documentation of API endpoints of HKPC TSL e-Order System",
# "VERSION": "1.0.0",
# "SERVE_PERMISSIONS": ["rest_framework.permissions.IsAdminUser"],
'TITLE': 'Your Project API',
'DESCRIPTION': 'Your project description',
'VERSION': '1.0.0',
'SERVE_INCLUDE_SCHEMA': False,
'SWAGGER_UI_DIST': 'SIDECAR', # shorthand to use the sidecar instead
'SWAGGER_UI_FAVICON_HREF': 'SIDECAR',
'REDOC_DIST': 'SIDECAR',
}
url.py
path("api/schema/", SpectacularAPIView.as_view(), name="api-schema"),
path('api/schema/swagger-ui/', SpectacularSwaggerView.as_view(url_name='api-schema'), name='swagger-ui'),
path('api/schema/redoc/', SpectacularRedocView.as_view(url_name='api-schema'), name='redoc')
异常打印
ERROR 2023-11-21 14:37:58,973 log 13428 16804 Internal Server Error: /api/schema/
Traceback (most recent call last):
File "c:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\atang\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 81, in inner
return func(*args, **kwds)
^^^^^^^^^^^^^^^^^^^
File "c:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\django\views\decorators\csrf.py", line 56, in wrapper_view
return view_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\django\views\generic\base.py", line 104, in view
return self.dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\rest_framework\views.py", line 509, in dispatch
response = self.handle_exception(exc)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\rest_framework\views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "c:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
raise exc
File "c:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\rest_framework\views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\drf_spectacular\views.py", line 83, in get
return self._get_schema_response(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\drf_spectacular\views.py", line 91, in _get_schema_response
data=generator.get_schema(request=request, public=self.serve_public),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\drf_spectacular\generators.py", line 268, in get_schema
paths=self.parse(request, public),
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\atang\Desktop\github\hkpc-tsl-system-main-env\Lib\site-packages\drf_spectacular\generators.py", line 233, in parse
assert isinstance(view.schema, AutoSchema), (
AssertionError: Incompatible AutoSchema used on View <class 'tsl_backend.fgr_api.views.auth.AuthView'>. Is DRF's DEFAULT_SCHEMA_CLASS pointing to "drf_spectacular.openapi.AutoSchema" or any other drf-spectacular compatible AutoSchema?
3.疑问
注册此app,会有一个黑名单表,当jwt令牌过期自动加入黑名单
'rest_framework_simplejwt.token_blacklist' 黑名单
python写入csv数字过大导致科学技术
import csv
>>> writer = csv.writer(output)
>>> writer.writerow((ISBN + '\t'))