我正在考虑从pip和virtualenv切换到pipenv
但在研究了文档后,我仍然对pipenv的创建者如何构建部署工作流程感到茫然.
例:
在开发中,我有一个"Pipfile"和一个定义环境的"Pipfile.lock".
使用我想部署的部署脚本
1)通过Github将"git pull"发送到生产服务器
2)"pipenv install"创建/刷新部署用户的主目录中的环境
但是我需要一个特定方向的venv,它已经在systemd或supervisor中配置了
例如:
__PRE__
pipenv在某些位置创建环境,例如:/home/ultimo/.local/share/virtualenvs/application_xy-jvrv1OSi
使用pipenv部署应用程序的预期工作流程是什么?
我有一个非常标准的烧瓶、SQLAlchemy 和带有 Postgresql DB 的 AWS RDS 设置。
在正在运行的系统上更改 RDS SSL 证书后,应用程序 (flask) 显示以下异常并且无法从中恢复。
(psycopg2.errors.AdminShutdown) 由于管理员命令而终止连接 SSL 连接已意外关闭
我以这种方式初始化数据库(标准方式):
app = Flask(__name__)
db = SQLAlchemy()
db.init_app(app)
Run Code Online (Sandbox Code Playgroud)
上述异常发生在标准数据库查询期间:
r = MyModel.query.filter(foo == bar).all()
Run Code Online (Sandbox Code Playgroud)
如何使数据库连接自恢复?
我怎样才能捕捉到这个异常?
如何在Admin之外调用上传小部件?使用下面的标准表格不起作用.小部件已损坏.
forms.py
class PhotoAdd(forms.ModelForm):
class Meta:
model = Photo
fields = ('ImageFilerField',)
views.py
def photoadd(request):
context={}
context['form'] = PhotoAdd()
render(request, 'template.html', context)
template.html
{{ form }}
Run Code Online (Sandbox Code Playgroud)
文档中绝对没有提到这一点.如何在管理员外上传照片?
编辑:(从上面的django添加生成的代码)
<label for="id_doc_pic">Doc pic:</label>
</th>
<td>
<span class="filerFile">
<img id="id_doc_pic_thumbnail_img" src="/static/filer/icons/nofile_48x48.png" class="quiet" alt="no file selected" />
<span id="id_doc_pic_description_txt"></span>
<a href="/admin/filer/folder/last/?_to_field=file_ptr" class="related-lookup" id="lookup_id_doc_pic" title="Lookup">
<img src="/static/admin/img/icon_searchbox.png" width="16" height="16" alt="Lookup" /></a><img id="id_doc_pic_clear" class="filerClearer" src="/static/admin/img/icon_deletelink.gif" width="10" height="10" alt="Clear" title="Clear" style="display: none;" /><br />
<input class="vForeignKeyRawIdAdminField" id="id_doc_pic" name="doc_pic" type="text" />
<script type="text/javascript" id="id_doc_pic_javascript">
django.jQuery(document).ready(function(){
var plus = …Run Code Online (Sandbox Code Playgroud) 我有一个非常标准的flask-socket.io应用程序:
server:eventlet我使用以下命令启动应用程序:socketio.run(app,host ='0.0.0.0')
经常但并不总是我有某种超时:
Traceback (most recent call last):
File "/projects/ici_chat_prototype01/env/lib/python3.5/site-packages/eventlet/wsgi.py", line 507, in handle_one_response
result = self.application(self.environ, start_response)
File "/projects/ici_chat_prototype01/env/lib/python3.5/site-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/projects/ici_chat_prototype01/env/lib/python3.5/site-packages/flask_socketio/__init__.py", line 42, in __call__
start_response)
File "/projects/ici_chat_prototype01/env/lib/python3.5/site-packages/engineio/middleware.py", line 47, in __call__
return self.engineio_app.handle_request(environ, start_response)
File "/projects/ici_chat_prototype01/env/lib/python3.5/site-packages/socketio/server.py", line 360, in handle_request
return self.eio.handle_request(environ, start_response)
File "/projects/ici_chat_prototype01/env/lib/python3.5/site-packages/engineio/server.py", line 267, in handle_request
environ, start_response)
File "/projects/ici_chat_prototype01/env/lib/python3.5/site-packages/engineio/socket.py", line 89, in handle_get_request
start_response)
File "/projects/ici_chat_prototype01/env/lib/python3.5/site-packages/engineio/socket.py", line 130, in _upgrade_websocket
return ws(environ, start_response)
File "/projects/ici_chat_prototype01/env/lib/python3.5/site-packages/engineio/async_eventlet.py", line …Run Code Online (Sandbox Code Playgroud) 我正在视图中生成报告下载并在处理 POST 数据后开始下载。这意味着用户发送表单并开始下载:
视图.py
def export(request):
if request.method == 'POST' and 'export_treat' in request.POST:
form1 = TransExport(request.POST, instance= obj)
if form1.is_valid():
...
...
response=HttpResponse(ds.xls,content_type="application/xls")
response['Content-Disposition'] = 'attachment; filename="Report_Behandlungen.xls"'
return response
Run Code Online (Sandbox Code Playgroud)
我需要的是下载(或重定向)后的页面刷新。我怎样才能做到这一点?
我的提交不会保存对数据库的任何更改:
# project/models.py
from project import db
from sqlalchemy.dialects.postgresql import JSON
class Customer(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
clientid = db.Column(db.String(64))
...
contextjason = db.Column(JSON)
Run Code Online (Sandbox Code Playgroud)
# project/__init__.py
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
db = SQLAlchemy(app)
from project.models import Customer
custObj = Customer.query.filter(Customer.custid == custid).first()
print(custObj.contextjason) # works fine
custObj.contextjason = { 'foo':'bar', 'so':'be it'}
db.session.commit()
Run Code Online (Sandbox Code Playgroud)
提交不会向数据库提交任何更改。实际上,我不知道它在后台做什么。
谁能告诉我为什么我没有数据库更新?
我可以告诉提交以某种方式记录它在做什么(也许是 SQL 明智的)?
编辑:
使用 SQLALCHEMY_ECHO=True
我得到这个提交:
2018-05-23 16:42:17,102 信息 sqlalchemy.engine.base.Engine COMMIT
我有这个依赖问题:
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Warning: Your dependencies could not be resolved. You likely have a mismatch in your sub-dependencies.
You can use $ pipenv install --skip-lock to bypass this mechanism, then run $ pipenv graph to inspect the situation.
Could not find a version that matches futures<4.0.0,>=2.2.0,>=3.2.0; python_version < "3.2"
Tried: 0.2.python3, 0.1, 0.2, 1.0, 2.0, 2.1, 2.1.1, 2.1.2, 2.1.3, 2.1.4, 2.1.5, 2.1.5, 2.1.6, 2.1.6, 2.2.0, 2.2.0, 3.0.0, 3.0.0, 3.0.1, 3.0.1, 3.0.2, 3.0.2, …Run Code Online (Sandbox Code Playgroud) 在阅读了数小时的文档和资源后,我请求您的帮助。
我在 API V2 项目“xxx1”上有一个对话流代理
我为“xxx1”创建了一个服务帐户并附加了角色“Dialogflow API Client”
我下载了带有凭据的 JSON 文件。
我在 python 中创建会话:
session = dialogflow.SessionsClient(
{
'credentials': {
'client_email': 'serviceaccountemail...',
'private_key': '-----BEGIN PRIVATE KEY----- ...',
},
'project_id': 'xxx1',
}
)
Run Code Online (Sandbox Code Playgroud)
这里没有问题。
如果我在运行时调用 Dialogflow API,我会收到:
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
status = StatusCode.PERMISSION_DENIED
details = "IAM permission 'dialogflow.sessions.detectIntent' on 'projects/xxx1/agent' denied."
debug_error_string = "{"created":"@1534320091.581347198","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1095,"grpc_message":"IAM permission 'dialogflow.sessions.detectIntent' on 'projects/xxx1/agent' denied.","grpc_status":7}"
Run Code Online (Sandbox Code Playgroud)
对我来说,这听起来好像权限不够。但是我对其他代理使用相同的角色,并且工作正常。
模型
class Photo(models.Model):
doc_pic = models.ImageField(upload_to='specialist/', default='', null=True, blank=True, max_length=250)
doctor = models.ForeignKey(Doctor, blank=True, null=True, on_delete=models.SET_NULL, related_name='photos')
Run Code Online (Sandbox Code Playgroud)
我查询照片
temp = Photo.objects.all()
Run Code Online (Sandbox Code Playgroud)
现在我想要保存在医生字段中的医生 ID(对于第一个元素)
print(temp[0].doctor)
Run Code Online (Sandbox Code Playgroud)
我收到了 Doctor 对象。但我想要数字 ID。我怎么能得到那个?
我知道我可以得到它
temp[0].doctor.id
Run Code Online (Sandbox Code Playgroud)
但这会向我想避免的数据库提交另一个查询。
如果我为当前使用的 Flask 部署构建 docker 映像:
Dockerfile
FROM python:3.6-alpine
COPY . /app
WORKDIR /app
RUN apk add --virtual build-deps gcc python-dev musl-dev && \
apk add postgresql-dev
RUN pip install pipenv
RUN pipenv install --system --deploy
EXPOSE 5005
ENV FLASK_APP=app/__init__.py
ENV FLASK_RUN_PORT=5005
CMD flask run --host=0.0.0.0
Run Code Online (Sandbox Code Playgroud)
不幸的是,这会导致容器大小约为 500MB。原始 Alpine 图像约为 40MB。主要的大小增加来自于安装 psycopg2 和 gcc(psycopg2 需要)。
我真的很想减小该图像的尺寸。任何想法表示赞赏。
python ×6
django ×3
pipenv ×2
sqlalchemy ×2
alpine-linux ×1
django-filer ×1
docker ×1
flask ×1
httpresponse ×1
python-3.5 ×1
python-3.x ×1
redirect ×1
refresh ×1
websocket ×1