我想打印 spacy 语言模型“en”中每个词向量的维数。我安装了语言模型和 spacy。我有以下几行代码
import spacy
nlp =spacy.load('en')
dim = nlp.vocab.vectors_length
print(dim)
Run Code Online (Sandbox Code Playgroud)
它给出 0。
有人可以帮我弄这个吗?
计划的作业执行两次,差异以纳秒为单位。我在task.py中有一个任务如下
def print_hello():
print("time-->",datetime.datetime.now())
print("hello")
def print_world():
print("time-->",datetime.datetime.now())
print("hello")
scheduler = BackgroundScheduler()
scheduler1 = BackgroundScheduler()
Run Code Online (Sandbox Code Playgroud)
从应用程序文件夹中添加 app.py,包含以下代码行。
from django.apps import AppConfig
from datetime import date
class ExploitDataConfig(AppConfig):
name = 'exploit_data'
def ready(self):
from exploit_data import task
task.scheduler.add_job(task.print_hello, 'interval', minutes=5)
task.scheduler1.add_job(task.print_world, 'interval', minutes=5
task.scheduler.start()
task.scheduler1.start()
Run Code Online (Sandbox Code Playgroud)
我希望它仅以5 分钟的间隔 执行一次。任何帮助都是值得赞赏的..
场景:我有组和权限,权限与组关联,并且该组与用户关联。现在我尝试通过DjangoModelPermissions实现视图的权限
这对于实现查询集的以下代码行效果很好;
class UpdateCampaignView(generics.UpdateAPIView):
authentication_classes = [TokenAuthentication]
permission_classes = [DjangoModelPermissions]
queryset = Campaign.objects.all()
serializer_class = UpdateCampaignSerializer
def get_object(self):
campaign_id = self.request.data.get("id")
return Campaign.objects.get(id =campaign_id)
Run Code Online (Sandbox Code Playgroud)
但我想将其实现为基于类的 APIView,无需使用 queryset 关键字,如下所示:
class RetrieveCampaignView(APIView):
authentication_classes = [TokenAuthentication]
permission_classes = [DjangoModelPermissions] #this is what i want to do
def get(self, request, *args, **kwargs):
try:
campaign = Campaign.objects.get(id = request.data.get("id"))
searializer = GetCampaignSerializer(campaign)
return Response({"status":True , "payload":searializer.data})
except:
return Response({"status":False}, status=status.HTTP_404_NOT_FOUND)
Run Code Online (Sandbox Code Playgroud)
但这给出了以下错误:
djangorest框架错误无法在未设置.queryset或没有.get_queryset()方法的视图上应用DjangoModelPermissions
python django django-models django-views django-rest-framework