静态文件application_readable的用法 [英] Static files application_readable usage

查看:87
本文介绍了静态文件application_readable的用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试了解application_readable静态url处理程序字段的工作原理。我正在使用SDK 1.7.7版本,并且在我的开发环境中的应用程序中将此设置为true,但我似乎无法真正阅读该文件:

 #app.yaml 

- url:/ test
static_dir:application / static / test
application_readable:true

#app.py

path = os.path.join(os.path.split(__ file __)[0],'static / test / test.png')
self.response.out.write('寻找%s ...'%路径)
self.response.out.write(os.path.exists(path))
self.response.out .write(\\\

path ='/application/static/test/test.png'
self.response.out.write('寻找%s ...'%路径)
self.response.out.write(os.path.exists(path))
self.response.out.write(\\\

path ='application / static /test/test.png'
self.response.out.write('寻找%s ...'%路径)
self.response.out.write(os.path.exists(path ))
self.response.out.write(\\\

path ='/static/test/test.png'
self。 response.out.write('寻找%s ...'%路径)
self.response.out.write(os.path.exists(path))
self.response.out.write ('\\\

path ='static / test / test.png'
self.response.out.write('寻找%s ...'%路径)
self.response.out.write(os.path.exists(path))
self.response.out.write(\\\

path ='/test/test.png'
self.response.out.write('寻找%s ...'%路径)
self.response.out.write(os.path.exists(path))
self。 response.out.write(\\\

path ='test / test.png'
self.response.out.write('寻找%s ...'%路径)
self.response.out.write(os.path.exists(path))
self.response.out.write(\\\

path ='/test.png'
self.response.out.write('寻找%s ...'%路径)
self.response.out.write(os.path.exists(path))
self .response.out.write(\\\

path ='test.png'
self.response.out.write('寻找%s ...'%路径)
self.response.out.write(o s.path.exists(path))

但是没有一个工作:

 寻找/vagrant/test/application/static/test/test.png...False 
寻找/ application / static / test /test.png...False
寻找application / static / test / test.png ... False
寻找/static/test/test.png...False
Looking for static / test / test.png ... False
寻找/test/test.png...False
寻找test / test.png ... False
正在寻找/ test.png ... False
寻找test.png ... False

虽然该文件肯定存在:

  vagrant @ precise64:/ vagrant / kissyface $ ls -l / vagrant / test / application / static / test / test.png 
-rwxrwxrwx 1 vagrant vagrant 9920 5月3日18:13 /vagrant/test/application/static/test/test.png

任何人都可以告诉我我做错了什么吗?除了statis url处理文档中的简要描述和appengine sdk 1.7.6更新日志中的提及之外,我一直无法找到任何文档或示例代码。是否有一个实用程序类提供对这些文件的访问,或者我完全误解了application_readable实际上应该做什么?

概述

在您的系统上正确地执行 有些困难,但我可以告诉您什么对我有用。我们可以整天猜测可能会出现什么问题,但是实施一些有效的工作和倒退的工作通常比猜测更有成效;它可以是任何东西。



如果我猜测,我会说这个问题是:


  1. 错误的处理程序顺序

  2. 搞砸了python路径

  3. 搞砸python版本

  4. 使用janky旧SDK

  5. 内裤gnomes






如果不是猜测,而是实施了我在下面概述的项目,那么应该很简单地向后推理并找出为什么它不适合你。如果这个项目不起作用,那么你有一些工作要做。这个问题真的很讨厌(我不想帮你修复它)。如果它确实有效,那么你很幸运,因为你距离其他代码工作5到10分钟!



使用最新的python appengine来自 http://code.google.com/p/googleappengine/downloads/list 的SDK:

  google_appengine_1.8.0.zip 
71b5f3ee06dce0a7d6af32d65ae27272eac038cb



项目文件及其内容:



目录设置:



 
├──app.py
├──app.pyc
├──app.yaml
└──static
└──hi.txt



app.py:



  import webapp2 
import os
$ b class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers ['' Content-Type'] ='text / plain'
self.response.out.write('Hello,webapp World!\\\
'\
')

path = os.path .join(os.path.split(__ file __)[0],'static / hi.txt')
self.response.out.write(open(path).readlines()[0])

application = webapp2.WSGIApplication([('/.*',MainPage)])

app.pyc是该文件的(自动)编译版本。



app.yaml:



 













$:
- url:/ static
static_dir:static
ap plication_readable:true
- url:/.*
script:app.application



static / hi.txt:



  Ezra可以很好地看到这段文字;我不确定你为什么不能......嗨! 



会发生什么:



启动网络服务器从项目根目录:

  dev_appserver.py --port 80。 

您可能需要使用不同的端口号;这没什么大不了的。只需调整您选择的指示即可。



在浏览器中访问 http:// localhost /



Http response:



  INFO 2013-05-14 09 :45:57,372 server.py:585] default:GET / HTTP / 1.1200 85 



浏览器输出:




Hello,webapp World!



Ezra可以看到这段文字精细;我不确定为什么你不能...嗨!




访问 http:// localhost浏览器中的/static/hi.txt



Http响应:



  INFO 2013-05-14 09:48:42,785 server.py:585]默认:GET /static/hi.txt HTTP / 1.1200 63 

浏览器输出:




Ezra可以看到这个文字很好;我不确定你为什么不能......嗨!




打破它:



如果我从app.yaml中删除 application_readable:true 行:



访问 http:// localhost / 在浏览器中:



Http响应:



 错误2013-05-14 09:51:13,290 webapp2.py:1528] [Errno 13]文件无法访问:'... / static / hi.txt'



浏览器输出:




500内部服务器错误



服务器有错误或无法执行请求的操作。




下一步做什么:



希望你能从这个例子中倒退。如果它不适合你,你注定要失败。享受在五月中旬的阳光下度过漫长的路程,并尝试(安装/取消)安装东西,以便让这件事情继续下去。顶部的列表是我尝试的列表,不知道任何细节并排除了编程错误。祝你好运!


I've been trying to understand how the application_readable static url handler field works. I'm using SDK version 1.7.7 and I've set this to true on an application in my dev environment, but I can't seem to actually read the file:

# app.yaml

- url: /test
  static_dir: application/static/test
  application_readable: true

# app.py

path = os.path.join(os.path.split(__file__)[0], 'static/test/test.png')
self.response.out.write('Looking for %s...' % path)
self.response.out.write(os.path.exists(path))
self.response.out.write("\n")
path = '/application/static/test/test.png'
self.response.out.write('Looking for %s...' % path)
self.response.out.write(os.path.exists(path))
self.response.out.write("\n")
path = 'application/static/test/test.png'
self.response.out.write('Looking for %s...' % path)
self.response.out.write(os.path.exists(path))
self.response.out.write("\n")
path = '/static/test/test.png'
self.response.out.write('Looking for %s...' % path)
self.response.out.write(os.path.exists(path))
self.response.out.write("\n")
path = 'static/test/test.png'
self.response.out.write('Looking for %s...' % path)
self.response.out.write(os.path.exists(path))
self.response.out.write("\n")
path = '/test/test.png'
self.response.out.write('Looking for %s...' % path)
self.response.out.write(os.path.exists(path))
self.response.out.write("\n")
path = 'test/test.png'
self.response.out.write('Looking for %s...' % path)
self.response.out.write(os.path.exists(path))
self.response.out.write("\n")
path = '/test.png'
self.response.out.write('Looking for %s...' % path)
self.response.out.write(os.path.exists(path))
self.response.out.write("\n")
path = 'test.png'
self.response.out.write('Looking for %s...' % path)
self.response.out.write(os.path.exists(path))

But none of those work:

Looking for /vagrant/test/application/static/test/test.png...False
Looking for /application/static/test/test.png...False
Looking for application/static/test/test.png...False
Looking for /static/test/test.png...False
Looking for static/test/test.png...False
Looking for /test/test.png...False
Looking for test/test.png...False
Looking for /test.png...False
Looking for test.png...False

Though the file definitely exists:

vagrant@precise64:/vagrant/kissyface$ ls -l /vagrant/test/application/static/test/test.png
-rwxrwxrwx 1 vagrant vagrant 9920 May  3 18:13 /vagrant/test/application/static/test/test.png

Can anyone tell me what I'm doing wrong? I haven't been able to find any documentation or example code for this beyond the brief description in the statis url handler docs and a mention in the appengine sdk 1.7.6 changelog. Is there a utility class that provides access to these files, or am I completely misinterpreting what application_readable is actually supposed to do?

解决方案

Overview

It's somewhat difficult to reason about what exactly is going on on your system, but I can tell you what works on mine. We can speculate all day about what could be wrong, but implementing something that works and working backwards is usually more productive than guessing; it could be anything.

If I were to guess, I'd say that the problem is:

  1. Incorrect handler order
  2. Screwed up python paths
  3. Screwed up python versions
  4. Using a janky old SDK
  5. Underpants gnomes


If, instead of guessing, you implement the project I've outlined below, it should be pretty simple to reason backward and find out why it's not working for you. If this project doesn't work, you've got some work to do. The problem's really nasty (and I don't want to help you fix it). If it does work, you're in luck, since you're 5 or 10 minutes away from having the rest of your code working too!

Using the latest python appengine SDK from http://code.google.com/p/googleappengine/downloads/list:

google_appengine_1.8.0.zip
71b5f3ee06dce0a7d6af32d65ae27272eac038cb

Project files and their contents:

Directory Setup:

.
├── app.py
├── app.pyc
├── app.yaml
└── static
    └── hi.txt

app.py:

import webapp2
import os

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('Hello, webapp World!\n\n')

        path = os.path.join(os.path.split(__file__)[0], 'static/hi.txt')
        self.response.out.write(open(path).readlines()[0])

application = webapp2.WSGIApplication([('/.*', MainPage)])

app.pyc is the (automatically) compiled version of this file.

app.yaml:

application: myapp
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /static
  static_dir: static
  application_readable: true
- url: /.*
  script: app.application

static/hi.txt:

Ezra can see this text fine; I'm not sure why you can't... Hi!

What happens:

Start the webserver from the project root:

 dev_appserver.py --port 80 .

You might have to use a different port number; it's no big deal. Just adjust the instructions that follow for the one you choose.

Visiting http://localhost/ in the browser:

Http response:

INFO     2013-05-14 09:45:57,372 server.py:585] default: "GET / HTTP/1.1" 200 85

Browser output:

Hello, webapp World!

Ezra can see this text fine; I'm not sure why you can't... Hi!

Visiting http://localhost/static/hi.txt in the browser:

Http response:

INFO     2013-05-14 09:48:42,785 server.py:585] default: "GET /static/hi.txt HTTP/1.1" 200 63

Browser output:

Ezra can see this text fine; I'm not sure why you can't... Hi!

Breaking it:

If I remove the application_readable: true line from app.yaml:

Visiting http://localhost/ in the browser:

Http Response:

ERROR    2013-05-14 09:51:13,290 webapp2.py:1528] [Errno 13] file not accessible: '.../static/hi.txt'

Browser output:

500 Internal Server Error

The server has either erred or is incapable of performing the requested operation.

What to do next:

Hopefully you can work backwards from this example. If it doesn't work for you, you're doomed. Enjoy spending a sunny mid-May afternoon trawling through paths and trying to (re/un)install things to get this frickin' thing going. The list at the top is a list of I'd try, without knowing any specifics and having ruled out programming error. Good luck!

这篇关于静态文件application_readable的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆