2012-06-03 22 views
0

我似乎無法找到任何地方。附加服務HTML沒有尾隨/在文件夾中

我有一個appengine項目,只是提供html頁面。但是,只有在文件名'正確'正確時才能正確加載文件。

I.e. mywebsite.com/lastproject/負荷完美

mywebsite.com/lastproject完全不

我希望在尾隨/留在網站正確加載加載。我錯過了什麼?

這裏是我的app.yaml

application: websitewithsubfolder 
version: 1 
runtime: python 
api_version: 1 

handlers: 

- url: (.*)/ 
    static_files: static\1/index.html 
    upload: static/index.html 

- url:/
    static_dir: static 

回答

0

@Shay意味着行應該是:

- url: (.*) 

這是一個路線處理所有URL請求,您將不會收到任何404錯誤,並且所有請求均由靜態 index.html頁面處理。您的第二條路線將不會被處理,因爲它更具體,並且在您的通用路線之後。

你想要更具體的路線上方捕捉所有路線。

application: websitewithsubfolder 
version: 1 
runtime: python 
api_version: 1 

handlers: 
- url: /static 
    static_dir: static 

- url: /favicon.ico 
    static_files: static/images/favicon.ico 
    upload: static/images/favicon.ico 
    mime_type: image/vnd.microsoft.icon 

- url: /robots.txt 
    static_files: robots.txt 
    upload: robots.txt 

- url: /(.*\.(gif|png|jpg)) 
    static_files: \1 
    upload: (.*\.(gif|png|jpg)) 

- url: /static/css 
    static_dir: static/css 

- url: /static/js 
    static_dir: static/js 

- url: (.*) 
    static_files: static/index.html 
    upload: static/index.html 

上面的app.yaml文件更符合您的需求。

我建議你閱讀app.yaml文檔,這些文檔詳細介紹了這一點。

+0

這似乎工作正常加載源HTML,但所有的資產都被槍殺。我多次得到以下錯誤。 :錯誤2012-06-03 15:56:50,916 dev_appserver.py:1983]讀取文件「/website/static/style/style.css/index.html」時遇到錯誤: [Errno 20]不是目錄:'website /static/style/style.css/index.html' – oberbaum

+0

@norskben我用我的應用程序中使用的一些其他示例更新了答案。 您確實需要閱讀[Google App Engine入門](https://developers.google.com/appengine/docs/python/gettingstarted/) 上面的app.yaml如果您將其修改爲您的應用程序,將會工作,但你有一個靜態的HTML頁面回答所有路線。爲了從應用程序引擎中獲得真正的好處,您需要創建一個*應用程序*。 –

0

在YAML文件你的第一個映射告訴AppEngine上「與以結尾的網址/應映射到......」。您沒有任何映射到不以/結尾的內容。

這一切映射到一個名爲靜態/ HTML文件夾(未經測試讓我知道,如果它的工作原理)

- url: /.* 
    static_dir: static/html 
    mime_type: text/html 
+0

如果可能,你可以舉個例子。我真的不熟悉這個語法。謝謝! – oberbaum