Cookiecutter

快速初始化一个项目:cookiecutter 示例来源于 cookiecutter-django项目 usage pip install "cookiecutter>=1.7.0" cookiecutter https://github.com/cookiecutter/cookiecutter-django 环境提供:local、production 网络 pycharm 使用 debug 模式的时候提示 2024-01-26T03:11:17.734227227Z PostgreSQL is available 2024-01-26T03:11:19.879595402Z Could not connect to host.docker.internal: 61147 2024-01-26T03:11:19.880258821Z Traceback (most recent call last): 2024-01-26T03:11:19.881026471Z File "/opt/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 463, in start_client 2024-01-26T03:11:19.881269144Z s.connect((host, port)) 2024-01-26T03:11:19.881290110Z socket.gaierror: [Errno -2] Name or service not known 2024-01-26T03:11:19.881302169Z Could not connect to host.docker.internal: 61147 2024-01-26T03:11:19.882321658Z Traceback (most recent call last): 2024-01-26T03:11:19.883283788Z File "/opt/.pycharm_helpers/pydev/pydevd.py", line 2206, in main 2024-01-26T03:11:19.883365970Z debugger.connect(host, port) 2024-01-26T03:11:19.883386459Z File "/opt/.pycharm_helpers/pydev/pydevd.py", line 670, in connect 2024-01-26T03:11:19.883393351Z s = start_client(host, port) 2024-01-26T03:11:19.883398270Z ^^^^^^^^^^^^^^^^^^^^^^^^ 2024-01-26T03:11:19.883471870Z File "/opt/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 463, in start_client 2024-01-26T03:11:19.883483991Z s.connect((host, port)) 2024-01-26T03:11:19.883490028Z socket.gaierror: [Errno -2] Name or service not known 我在 local.yml文件中针对 django service 加入如下配置可以解决 ...

January 24, 2024 · 1 min · Peter

Django打开gzip导致文件流content-length丢失

Django打开gzip导致文件流content-length丢失 code GZipMiddleware use gzip middleware will del response['Content-Length'] if response.streaming. nginx gzip is the same problem. If file feature is important. You’d better be independent from the api or system.

May 18, 2020 · 1 min · Peter

vue cors

利用proxy 解决 Django Vue 开发环境中的跨域问题 最近使用 Django+Vue的组合快速的做一个项目,前段之前有看过,但是只是👀会了,这次实际操作,在前后端分离后的开发环境中踩了坑。 环境 Django + DRF Django Channels,主要是websocket vue-admin-template,一个开源的项目,很多东西都有实现,新手可以用来改改就用,还能学习 开发环境: wsgi, 8000 asgi, 8001 vue, 9528 问题 想像在使用nginx一样的透明的使用开发环境 django已经配置了corsheaders middleware了 尝试 axios显示指定地址和端口到8000的服务上,解决了axios实例的访问,但是使用 el-upload的表单时,发现就不好使了,localhost和其他不同域,拿不到 cookie中的csrftoken,导致被 django拒绝 解决 在查看了各种文档后,最有效的方案是devServer的proxy,这是webpack提供的功能,使用的是http-proxy-middleware这个中间件,文档很详细,可以看看。 目标: 代理 /api的请求到8000端口的wsgi server 代理 /ws的请求到8001的asgi server /api ---> localhost:8000/api localhost:9528 (cookie) -- /ws ---> localhost:8001/ws vue.conf.js devServer: { ... proxy: { [process.env.VUE_APP_BASE_API]: { target: 'http://127.0.0.1:8000', changeOrigin: true, ws: false, pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }, cookieDomainRewrite: { '*': 'localhost' } }, '/ws': { target: 'ws://127.0.0.1:8001', // changeOrigin: true, secure: false, ws: true } } ... } 说明: ...

March 17, 2020 · 1 min · Peter