如何从 django 错误页面访问控制台?
当我的模板产生错误时,我希望能够检查我的变量/查询集,而不必import pdb; pdb.set_trace()每次我想从正在运行的应用程序进入控制台时都返回并添加到我的视图中。
我正在尝试查询 2 个表、凭据和集成。
我想检索每一条凭证记录WHERE user_id == current_user.id。我还想检索每个集成记录WHERE name == "Twitter"。
下面的查询运行并输出[[4, "Twitter"][3,"YouTube"]]
Credential.joins(:integration).where(user_id: current_user.id).pluck(:id, :name)
Run Code Online (Sandbox Code Playgroud)
下面的查询应该运行并生成[4, "Twitter"],但它却产生错误。
Credential.joins(:integration).where(user_id: current_user.id).where(integration: {name: 'Twitter'}).pluck(:id, :name)
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: missing FROM-clause entry for table "integration"
LINE 1: ...ration_id" WHERE "credentials"."user_id" = $1 AND "integrati...
Run Code Online (Sandbox Code Playgroud)
最终,我试图将我在其余代码中使用的集成列入白名单。如果我在 joins 参数中使用复数,Rails 会拒绝查询.joins(:integrations)。
我阅读了有关Rails验证的文档,但没有看到如何处理控制器中的错误.
问题 - 提交表单后是否render :new以及render :edit何时.save失败以显示错误的正确方法?
另外,有没有一种方法可以保持polls/new和polls/edit路由相同,就像最初加载表单时一样?
在我看来,我有@poll.errors.any? ... @poll.errors.full_messages.each do ...块.如果我的控制器中有以下代码,则成功调用这些错误,并且render :new是主要关注点:
class PollsController < ApplicationController
def create
@poll = Poll.create(poll_params)
if @poll.save
redirect_to polls_path
else
render :new
end
end
Run Code Online (Sandbox Code Playgroud)
表单显示,但我的路由从polls/new后面更改为polls并且没有构建任何选项.我也试过redirect_to new_poll_path但当然从头开始并没有显示任何错误.
在生物信息学方面,我们越来越多地使用基于群集的部署,如Kubernetes,Spark和Hadoop.术语POSIX存储不断出现在文档中.
POSIX存储和NFS块存储(EBS)有什么区别?这些术语是否可以互换?它基本上是指任何不是对象存储(S3)或Microsoft(SMB,CIFS)的东西吗?
在 Django REST Framework 中,我尝试将 API 根添加到具有基于类的视图的views.py。
错误:
$ http http://127.0.0.1:8000/api/
Error - django.urls.exceptions.NoReverseMatch: Reverse for 'SnippetListView' not found. 'SnippetList' is not a valid view function or pattern name.
Run Code Online (Sandbox Code Playgroud)
后端/views.py
from backend.models import *
from backend.serializers import *
from rest_framework import generics
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.reverse import reverse
@api_view(['GET'])
def api_root(request, format=None):
return Response({
'snippets': reverse('SnippetList')
# 'snippets': reverse('SnippetListView')
# 'snippets': reverse('snippet-list')
# 'snippets': reverse('snippet_list')
})
class SnippetList(generics.ListCreateAPIView):
queryset = Snippet.objects.all()
serializer_class = SnippetSerializer …Run Code Online (Sandbox Code Playgroud) 使用multinomial而不是直线上升来评估预测准确性的目的是什么argmax?
probs_Y = torch.softmax(model(test_batch, feature_1, feature_2), 1)
sampled_Y = torch.multinomial(probs_Y, 1)
argmax_Y = torch.max(probs_Y, 1)[1].view(-1, 1)
print('Accuracy of sampled predictions on the test set: {:.4f}%'.format(
(test_Y == sampled_Y.float()).sum().item() / len(test_Y) * 100))
print('Accuracy of argmax predictions on the test set: {:4f}%'.format(
(test_Y == argmax_Y.float()).sum().item() / len(test_Y) * 100))
Run Code Online (Sandbox Code Playgroud)
结果:
Accuracy of sampled predictions on the test set: 88.8889%
Accuracy of argmax predictions on the test set: 97.777778%
Run Code Online (Sandbox Code Playgroud)
阅读 pytorch 文档,看起来多项式是根据某种分布进行采样的 - 只是不确定这与评估准确性有什么关系。
我注意到多项式是非确定性的——这意味着它每次运行时都会输出不同的准确度,大概是通过包含不同的样本。
刚读完Nigel Poulton的The Kubernetes Book,但我对服务有点不解.
是否可以以某种方式将服务添加到部署清单中?或者服务是否必须自行发布?部署的全部目的不是指定应用程序运行所需的所有内容吗?
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: hello-deploy
spec:
replicas: 10
selector:
matchLabels:
app: hello-world
minReadySeconds: 10
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-pod
image: nigelpoulton/k8sbook : latest
ports:
- containerPort: 8080
Run Code Online (Sandbox Code Playgroud) django ×2
debugging ×1
django-views ×1
filesystems ×1
forms ×1
join ×1
kubernetes ×1
nfs ×1
posix ×1
postgresql ×1
pytorch ×1
storage ×1
validation ×1
werkzeug ×1