gpt4 book ai didi

快速 Steam 叶环

转载 作者:行者123 更新时间:2023-12-04 10:52:39 29 4
gpt4 key购买 nike

我试图从叶渲染器获得一个非常简单的结果,用于快速 Steam 的 for 循环。

我正在上传叶文件 HTML,因为它不接受此处格式正确的代码 -

enter image description here

下面的pizza.swift代码-

   import Foundation
import Vapor

struct pizza: Encodable, Content, Decodable {
var id: Int?
var name: String
var description: String
var price: Int
}

route.swift 代码如下 -
   import Routing
import Vapor

public func routes(_ router: Router) throws {
router.get { req -> Future <View> in
let Newyorker = pizza(id: 5, name: "statinisland", description: "impracticaljokers", price: 55)
let Traditional = pizza(id: 5, name: "rome", description: "pope", price: 55)
return try req.view().render("welcome",["Pizza":[Newyorker,Traditional]])
}



// Example of configuring a controller
let todoController = TodoController()
router.get("todos", use: todoController.index)
router.post("todos", use: todoController.create)
router.delete("todos", Todo.parameter, use: todoController.delete)
}

我期望的是——

比萨

欢迎来到世界上最好的披萨
  .statinisland
.rome

我得到的是 -

比萨

欢迎来到世界上最好的披萨
.#for (pizza in pizza) {
.
}

如果您需要更多信息,我可以上传。任何帮助将不胜感激。

编辑 - 我也在下面添加 configure.swift 代码 -
import FluentSQLite
import Vapor
import Leaf // added
/// Called before your application initializes.
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
// Register providers first
try services.register(FluentSQLiteProvider())

// Register routes to the router
let router = EngineRouter.default()
try routes(router)
services.register(router, as: Router.self)

// Register middleware
var middlewares = MiddlewareConfig() // Create _empty_ middleware config
// middlewares.use(FileMiddleware.self) // Serves files from `Public/` directory
middlewares.use(ErrorMiddleware.self) // Catches errors and converts to HTTP response
services.register(middlewares)

// Configure a SQLite database
let sqlite = try SQLiteDatabase(storage: .memory)

// Register the configured SQLite database to the database config.
var databases = DatabasesConfig()
databases.add(database: sqlite, as: .sqlite)
services.register(databases)

// Configure migrations
var migrations = MigrationConfig()
migrations.add(model: Todo.self, database: .sqlite)
services.register(migrations)
let leafProvider = LeafProvider() // added
try services.register(leafProvider) // added
config.prefer(LeafRenderer.self, for: ViewRenderer.self)// added
// http://localhost:8080/ already in use so adding new server http://localhost:8080/ below -
let serverConfigure = NIOServerConfig.default(hostname: "0.0.0.0", port: 9090)
services.register(serverConfigure)
}

最佳答案

有两个问题:

  • 您在 route 定义了一个关键的“披萨”,并在 .leaf 中使用了“披萨”文件。叶区分大小写。
  • 这很可能是 Leaf 中的一个错误。在 #for 之间引入一个空格和 (给我的工作应用程序造成了问题。
  • 关于快速 Steam 叶环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59397283/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com