小编Cla*_*ity的帖子

Django Rest Framework过滤计算的模型属性

抱歉新手问题.我有以下型号:

    class WeightSlip(models.Model):

        grossdate = models.DateTimeField(auto_now=False, auto_now_add=False)
        grossweight = models.DecimalField(max_digits=6, decimal_places=2, default=0)
        taredate = models.DateTimeField(auto_now=False, auto_now_add=False)
        tareweight = models.DecimalField(max_digits=6, decimal_places=2, default=0)
        vehicle = models.CharField(max_length=12)

        @property
        def netweight(self):
            return self.grossweight - self.tareweight

        @property
        def slipdate(self):
            if self.grossdate > self.taredate:
               return grossdate.date()
            else:
               return taredate.date()
Run Code Online (Sandbox Code Playgroud)

串行:

    class WeightSlipSerializer(serializers.ModelSerializer):

       class Meta:
          model = models.WeightSlip
          fields = ('grossdate', 'grossweight', 'taredate', 'tareweight', 'slipdate', 'netweight', 'vehicle')
          read_only_fields = ('slipdate', 'netweight')
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用django-rest-framework-filters来过滤计算出的'netweight'和'slipdate'属性:

    class WeightSlipFilter(FilterSet):

       class Meta:
           model = WeightSlip
           fields = ('slipdate', 'netweight', 'vehicle')
Run Code Online (Sandbox Code Playgroud)

这给了我一个错误: …

django django-filter django-filters django-rest-framework

10
推荐指数
1
解决办法
4321
查看次数

找不到模块:无法解析“反应”

我正在尝试将我的 Redux 商店连接到我的 React 项目,但我不断收到此错误:

../node_modules/react-redux/es/components/Provider.js 未找到模块:无法解析“C:\Users.\Documents..\node_modules\react-redux\es\components”中的“react”

我已经安装了react-redux并且redux(我相信 react-redux 对 redux 有一些依赖)

import { Provider} from 'react-redux';
Run Code Online (Sandbox Code Playgroud)

这就是给出错误的原因。

关于我可以做什么的任何建议?

reactjs react-native redux react-redux

5
推荐指数
1
解决办法
2万
查看次数

ModuleNotFoundError: 没有名为“wsgi”的模块

我打算使用 Heroku 托管它。但由于配置文件的问题,它不起作用。

这是我的 Procfile

-> web: gunicorn wsgi:app
Run Code Online (Sandbox Code Playgroud)

我试过这些东西。

->web : gunicorn wsgi.py
->web : gunicorn <myproject>.wsgi --log-file-
Run Code Online (Sandbox Code Playgroud)

我的 wsgi.py 代码

"""
WSGI config for config project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')

application = get_wsgi_application()


from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(application)
Run Code Online (Sandbox Code Playgroud)

这是我的 Heroku 日志

使用命令gunicorn wsgi:app 2019-09-13T06:06:27.409894+00:00 heroku[web.1]启动进程:状态从开始变为崩溃 2019-09-13T06:06:27.388714+00:00 heroku[web.1]:进程退出状态 3 2019-09-13T06:06:27.176179+00:00 app[web.1]: [2019-09-13 …

django heroku procfile

5
推荐指数
2
解决办法
1万
查看次数

当我使用扩展语法和解构时,Lint 显示错误

我有传播和解构运算符的问题。在 npm run lint:js 之后我会看到:

TypeError: Cannot read property 'type' of undefined
Occurred while linting C:\Users\USER\hq-manager-frontend\frontend\src\common\functions\projects.js:8
    at checkDestructured (C:\Users\USER\hq-manager-frontend\frontend\node_modules\eslint\lib\rules\no-useless-rename.js:104:43)
    at C:\Users\USER\hq-manager-frontend\frontend\node_modules\eslint\lib\linter\safe-emitter.js:45:58
Run Code Online (Sandbox Code Playgroud)

用于 ReactJs

project.employees.map(({ billedHours, employee }) => {
      const result = billedHours.reduce((res, current) => {
        const { date, ...others } = current;
        return {
          ...res,
          [date]: {
            hours: others,
            activeDates: [],
          },
        };
      }, {});

Run Code Online (Sandbox Code Playgroud)

.eslintrc.json

{
  "extends": ["airbnb", "prettier", "prettier/react"],
  "plugins": ["prettier"],
  "rules": {
    "react/jsx-filename-extension": [
      1,
      {
        "extensions": [".js", ".jsx"]
      }
    ],
    "react/jsx-props-no-spreading": 0,
    "react/no-unused-state": 1,
    "react/prop-types": …
Run Code Online (Sandbox Code Playgroud)

javascript lint destructuring spread

5
推荐指数
0
解决办法
452
查看次数

如何在 Javascript 中通过表单数据追加对象数组

我有依赖数组,它有多个对象。我需要通过表单数据发送该对象数组。我经历了很多尝试但无法得到正确的解决方案

    let dependents = [{name: "ashraf", number: 96546},{name: "himanshu", number: 98766}]
Run Code Online (Sandbox Code Playgroud)

我试图附加使用

    var data = new FormData();
    data.append("dependents[]", dependents)

Run Code Online (Sandbox Code Playgroud)

javascript arrays form-data reactjs

4
推荐指数
1
解决办法
1万
查看次数

如何获取ReactJS路由器硬编码参数

我有以下路线:

<Route path="/userstream/:user" component={ Profile } param="stream" />
Run Code Online (Sandbox Code Playgroud)

然后在我的组件中,我:user是这样的:this.props.match.params.user

但是,如何从硬编码参数中获取数据

先感谢您。

reactjs react-router

2
推荐指数
1
解决办法
45
查看次数

非字母数字字符串的Number.parseInt给出typeof'number'

这是正在发生的事情

typeof Number.parseInt('processed')版画'number'

在此处输入图片说明


但是如果Number.parseInt('processed')NaN

在此处输入图片说明

在此处输入图片说明

javascript

1
推荐指数
1
解决办法
144
查看次数

如何在 Django 中为石墨烯 graphql 编写测试

请任何人都可以帮助使用 django 测试石墨烯和 graphql

我尝试使用内置的 django 测试,但没有看到我使用的文件我使用了 pytest 但它在导入我的架构时抱怨 ModuleNotFoundError 我希望有人向我展示高级 python 的课程

class Query(ObjectType):
    calculate_price = Float(margin=Float(), exchangeRate=String(
    ), saleType=Argument(SaleType, required=True))

    def resolve_calculate_price(self, info, **kwargs):
        margin = kwargs.get('margin')
        exchangeRate = kwargs.get('exchangeRate')
        saleType = kwargs.get('saleType')

        request_from_coindesk = requests.get(
            url='https://api.coindesk.com/v1/bpi/currentprice.json')
        json_result_from_coindesk = json.dumps(request_from_coindesk.text)
        coindesk_result = json.loads(json_result_from_coindesk)
        result = json.loads(coindesk_result)

        rate_to_calculate = result["bpi"]["USD"]["rate_float"]

        if saleType == SaleType.sell:
            calculated_value = (margin/100) * rate_to_calculate
            new_rate = (rate_to_calculate - calculated_value) * 360
            print(18, new_rate)
            return new_rate
        elif saleType == SaleType.buy:
            calculated_value = (margin/100) * rate_to_calculate …
Run Code Online (Sandbox Code Playgroud)

python django graphql

1
推荐指数
1
解决办法
2179
查看次数

字体未在Reactjs中加载

这就是我在Reactjs中加载字体文件的方式

import styled from 'styled-components';
import fontUrls from './UberMove-Bold.ttf';
import fontUrls1 from './UberMove-Light.ttf';
import fontUrls2 from './UberMove-Medium.ttf';
import fontUrls3 from './UberMove-Regular.ttf';

const Fonts = styled`
    @font-face {
       font-familty: 'UberMove-Light';
       src: url(${fontUrls1}) format('truetype');
    }`;
Run Code Online (Sandbox Code Playgroud)

导入时抛出错误

未捕获的错误:无法创建组件的样式组件:@ font-f .ace {font-familty:'UberMove-Light'; src:url(,)format('truetype');}。

font-face reactjs styled-components

1
推荐指数
1
解决办法
45
查看次数

如何动态附加react div?

每次从服务器端套接字接收到一个对象时,都必须在DOM中附加一个新的div元素,其中包含一条消息。

而是再次重新覆盖div元素,并且仅生成一个div元素。

  state = {
    chatMessage: ''
  }

  componentDidMount() {
    socket.on('retrieve-chat-left', (data) => {

      var message = data.map(data => {
        console.log(data.name, data.message);
        return <ChatListLeft key={data._id} name={data.name} chatMessage={data.message} />
      });

      this.setState({
        chatMessage: message
      });
    });

  }

  render() {

    return (
      <div className="mainbodybar">
        {this.state.chatMessage}
      </div>
    )
  }

// ChatListLeft component

import React from 'react'

export default function ChatListLeft({ chatMessage, name }) {
  return (
    <div className="retrieve-chat-left">
      {chatMessage}
      {name}
    </div>
  )
}
Run Code Online (Sandbox Code Playgroud)

reactjs

0
推荐指数
1
解决办法
57
查看次数

“State”类型的参数不可分配给“never”类型的参数

我刚刚开始在 React 中使用 typescript。我尝试将它与 React useReducer 挂钩一起使用,但由于一个奇怪的错误而陷入困境。

这是我的代码:

    export interface ContractObj {
      company: string;
      negotiationRenewalDate: string;
      periodEnd: string;
      periodStart: string;
      scheduleForRenewal: boolean;
      contractId: string;
    }

    type State = {
      loading: boolean;
      error: boolean;
      contractsData: ContractObj[];
    };

    type Action =
      | { type: 'FETCH_SUCCESS'; payload: ContractObj[] }
      | { type: 'FETCH_ERROR'; payload: null };

    const initialState: State = {
      loading: true,
      error: false,
      contractsData: []
    };

    const reducer = (state: State, action: Action) => {
      switch (action.type) {
        case 'FETCH_SUCCESS':
          return …
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs react-hooks

0
推荐指数
1
解决办法
9522
查看次数