2013-02-25 61 views
0

響應我建立與python-flask.In一個網站的網頁我裝一個javascript file.Here的我的文件結構:瓶:查看功能並沒有換來js文件

/python 
    /static 
    /plugins 
    /themes 
     /default 
      /js 
      /my-js.js 
    /templates 
    /my-file.html 
    /venv 
    app.py 

我已經包含了我的 - js.js在my-file.html中。

還有其他腳本在這個js之前成功加載了頁面(與my-js.js在同一目錄中)。

當我打電話給我的文件與網址/static/themes/default/js/my-js.js 它說:ValueError: View function did not return a response與回溯:

Traceback (most recent call last): 
    File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 1701, in __call__ 
    return self.wsgi_app(environ, start_response) 
    File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 1689, in wsgi_app 
    response = self.make_response(self.handle_exception(e)) 
    File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 1687, in wsgi_app 
    response = self.full_dispatch_request() 
    File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 1361, in full_dispatch_request 
    response = self.make_response(rv) 
    File "/Users/ozcan/Library/Python/2.7/lib/python/site-packages/flask/app.py", line 1439, in make_response 
    raise ValueError('View function did not return a response') 
ValueError: View function did not return a response 

爲什麼happennig?我沒有爲靜態文件寫這樣的路由,比如這些js。其他js文件是如何加載的,這個不是?

回答

1

我能想到的一些事情。首先,它看起來像你想傳遞一個絕對路徑到my-js.js,當你真的想要一個相對路徑時,試試URL「static/themes/default/js/my-js.js」(沒有領先斜線),看看是否有幫助。另外,沒有看到你的python或Javascript,很難確認這一點,但你是否在響應對象中設置了適當的mimetype(它應該是application/javascript)?