相关疑难解决方法(0)

为什么开发服务器中的request.URL.Host和Scheme为空?

我是Go的新手.从文档中尝试了第一个hello,world,并希望从请求中读取Host和Scheme:

package hello

import (
    "fmt"
    "http"
)

func init() {
    http.HandleFunc("/", handler)
}

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Host: " + r.URL.Host + " Scheme: " + r.URL.Scheme)
}
Run Code Online (Sandbox Code Playgroud)

但他们的价值观都是空白的.为什么?

go httpserver

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

FastAPI:从视图名称(路由名称)中检索 URL

假设我有以下观点,

from fastapi import FastAPI

app = FastAPI()


@app.get('/hello/')
def hello_world():
    return {"msg": "Hello World"}


@app.get('/hello/{number}/')
def hello_world_number(number: int):
    return {"msg": "Hello World Number", "number": number}
Run Code Online (Sandbox Code Playgroud)

我一直在 Flask 和 Django 中使用这些函数

所以,我怎样才能获得/建立的网址,hello_worldhello_world_number以类似的方式?

python python-3.x fastapi

9
推荐指数
2
解决办法
5233
查看次数

标签 统计

fastapi ×1

go ×1

httpserver ×1

python ×1

python-3.x ×1