有人可以告诉我这段代码有什么问题吗

时间:2020-07-10 05:34:52

标签: python discord discord.py

import { NestFactory } from '@nestjs/core';

import{SwaggerModule,DocumentBuilder} from '@nestjs/swagger'

import { AppModule } from './app.module';

async function bootstrap() {

  const app = await NestFactory.create(AppModule);
 
  const options = new DocumentBuilder()

    .setTitle('My API')

    .setDescription('API description')

    .setVersion('1.0')

    .build();

  const document = SwaggerModule.createDocument(app, options);

  SwaggerModule.setup('api', app, document);


  await app.listen(3000);

}
bootstrap();

//controller

@Post()

addProduct(

    @Body('title') title:string,
    @Body('price') price:number,


):any{

    const idFromService=this.productserive.addNewProduct(title,price);

    return idFromService;

}

//productservice

export class ProductService {

  products:Product[]=[]; 
 
    addNewProduct(title:string,price:number){

        const id=uId();

        const newproduct=new Product(id,title,price);

        this.products.push(newproduct);

        return {title,price};

    }

}

运行此代码时出现此错误:

reference

我真的不知道这段代码有什么问题,我才刚开始,所以很抱歉这是一个愚蠢的问题!

1 个答案:

答案 0 :(得分:5)

f''字符串中,如果您需要使用其他字符串访问内容,则最好使用其他引号类型。

在这种情况下:

value=f'{data['mainKey']} aes key'

是无效的语法,因为您在字符串文字中包含多个引号。在这种情况下,正确的方法是:

value=f'{data["mainKey"]} aes key'

请注意使用双引号。其他选项包括:

value=f"{data['mainKey']} aes key"

value=f'''{data['mainKey']} aes key'''

value=f"""{data["mainKey"]} aes key"""

所有这些选项均有效且有用。