我已经尽可能地查看了所有内容,但没有找到我遇到的问题的答案。我花了几个小时在这,发现无济于事。
我的前端在项目下或应用程序树下使用静态文件夹显示所有图像和 css。
在我进行更改以使用动态 url 并从项目文件夹(一个文件夹向下)创建静态文件夹后,我的图像突然消失了,css 仍然可以直接路径或动态工作。
我已经对图像进行了相同的尝试,直接路径(因为文件夹的副本仍然保留在项目文件夹中)直接路径不起作用,动态路径也不起作用。
它也不返回 404,在第一次加载时,它返回 200,在第二次 304 时返回,就好像图像在屏幕上一样,但它不是。只是没有错误,但不存在该死的图像。让我感到困惑的是 css 可以工作,但图像不显示。
波纹管是我的代码。
---|settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static"),
#'/var/www/static/',
]
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn")
Run Code Online (Sandbox Code Playgroud)
---|url.py
if settings.DEBUG == True:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Run Code Online (Sandbox Code Playgroud)
---|main.html(模板)
{% load staticfiles %}
<img src={% static "images/banner_top.png" %}>
Run Code Online (Sandbox Code Playgroud)
或者
<img src="..static/images/banner_top.png">
Run Code Online (Sandbox Code Playgroud)
或者
<img src="static/images/banner_top.png">
Run Code Online (Sandbox Code Playgroud)
在浏览器上,图像不显示,但后端显示 200 和图像的正确路径。
http://127.0.0.1:8000/static/images/banner_top.png
[22/Oct/2016 22:32:10] "GET /static/images/banner_top.png HTTP/1.1" 200 0
Run Code Online (Sandbox Code Playgroud)
这是标题
一般的
Request URL:http://127.0.0.1:8000/static/images/banner_top.png
Request Method:GET
Status Code:200 OK
Remote Address:127.0.0.1:8000
Run Code Online (Sandbox Code Playgroud)
要求
Content-Length:0
Content-Type:image/png …Run Code Online (Sandbox Code Playgroud) 如果我在main或func home上的任何地方使用chan,应用程序会运行,但它并不真正起作用.没有错误抛出,但是,它不起作用.如果删除通道引用,它将恢复工作.通过在结构或全局通道中使用chan,应用程序停止工作.
在一个GET请求时,它返回h.Message从func home
由代码添加任何频道,GET请求不会返回消息.
https://play.golang.org/p/-ZVcLhZRRRG
package main
import (
"fmt"
"net/http"
"github.com/gorilla/websocket"
// _ "github.com/go-sql-driver/mysql"
)
type WMessage struct {
Message string `json:"message"`
ch chan string
}
var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool {
return true
},
}
var Chann chan string
func (h *WMessage) home(w http.ResponseWriter, r *http.Request) {
h.Message = "hey this is the message from home"
fmt.Fprintln(w, h.Message)
fmt.Println(<-h.ch)
}
func main() { …Run Code Online (Sandbox Code Playgroud)