python - 在 python 中的字符串中使用冒号

标签 python google-app-engine

我正在使用 python 2.6.5 为谷歌应用引擎开发应用程序 - 我不太熟悉 python,但我正在学习。

我正在尝试将 url 放入字符串中,因此 variable = "string http://domain.name "

然后我将字符串打印出来。问题是,如果冒号(在 http 之后)在字符串中,我不会得到任何输出,我也不知道为什么。

我试过用以下方法转义字符串:

  • """http://domain.name"""
  • r"http://domain.name"
  • "http\://domain.name"
  • "http\://domain.name"
  • "http\\://domain.name"
  • "http://domain.name"

它们似乎都不起作用,我不确定还能尝试什么

上下文是这样的

variables.py 是:

...
HOST_URL = "http://domain.name"
...

示例注销.py

import variables
import sys

...

class Logout(webapp.RequestHandler):
    """ RequestHandler for when a user wishes to logout from the system."""
    def post(self):
        self.get()

    def get(self):
        print(variables.HOST_URL)
        print('hi')
        self.redirect(variables.HOST_URL)
        sys.exit()

在文件 functions.py 中

import variables
import sys

...

def sendhome(requesthandler)
    print 'go to '+variables.HOST_URL
    requesthandler.redirect(variables.HOST_URL)
    sys.exit()

从如下上下文中调用:

from functions import sendhome

...

class Logout(webapp.RequestHandler):
    """ RequestHandler for when a user wishes to logout from the system."""
    def post(self):
        self.get()

    def get(self):
        sendhome(self)

任何帮助将不胜感激

谢谢

最佳答案

如果我没记错的话,GAE 使用 WSGI,你不只是打印东西,你应该返回一个正确的 HTTP 响应对象(它不是 PHP)。

我想如果您使用 firefox+firebug 访问该页面并查看 network->header,您会看到浏览器将 http: 作为值为“//domain.name”的 HTTP header 。

已编辑:顺便说一句,你不应该使用“self.response.out.write”而不是“print”吗?

关于python - 在 python 中的字符串中使用冒号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4092159/

相关文章:

Python HDFS : Cannot read file

python - 使用 XLRD 模块在导入的 excel 文件中搜索字符串

python - 在 Python 中将 .dbf 批量转换为 .csv

javascript - 如何将电子邮件添加到 Stripe 自定义收据表单(错误 : Received unknown parameter: email)

python - 在合并/左连接期间替换数据框中的 NaN

python - 在 Pandas 中,当使用 read_csv() 时,如何将 NaN 分配给不是预期 dtype 的值?

google-app-engine - 更新实体的属性而不从 NDB 检索实体

java - 如何创建自增主键?

google-app-engine - 谷歌 AppEngine 管道 API

python - GAE blobstore - 以编程方式上传文件