Django不能在网址中加引号字符吗? [英] Django can't have quoted characters in urls?

查看:53
本文介绍了Django不能在网址中加引号字符吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注此线程,并由Peppergrower采用该代码.但是,当我将加密的加引号的字符添加到url并尝试访问该url时,Django失败,并出现以下错误:

I'm following this thread and adopt the code by peppergrower. But when I add the encrypted and quoted characters to the url and try access this url, Django failed with the following errors:

回溯(最近通话最近一次):

Traceback (most recent call last):

文件"C:\ Python27 \ lib \ site-packages \ django \ core \ servers \ basehttp.py",行283,在运行中self.result =应用程序(self.environ,self.start_response)

File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 283, in run self.result = application(self.environ, self.start_response)

文件"C:\ Python27 \ lib \ site-packages \ django \ contrib \ staticfiles \ handlers.py",第68行,致电返回self.application(环境,start_response)

File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 68, in call return self.application(environ, start_response)

文件"C:\ Python27 \ lib \ site-packages \ django \ core \ handlers \ wsgi.py",第264行,在致电中logger.warning('Bad Request(UnicodeDecodeError):%s'%request.path,

File "C:\Python27\lib\site-packages\django\core\handlers\wsgi.py", line 264, in call logger.warning('Bad Request (UnicodeDecodeError): %s' % request.path,

UnboundLocalError:之前引用的本地变量"request"作业

UnboundLocalError: local variable 'request' referenced before assignment

此类网址示例为

A sample url of such kind is http://localhost:8000/customer/unsubscribe/%F1%CDE%A2%9DL%BF%21W%60%FF%04%D2%D2%3B%B1%FB%C9%8Ff%89%06O%FFY%E2_%16%9BnPM/. I notice that as long as % appears in the url, Django would throw above exceptions. It didn't make much sense since the quoted characters already have zero unicodes.

我正在使用Django 1.3.1

I'm using Django 1.3.1

推荐答案

有一些与此问题相关的Django票证 https://code.djangoproject.com/ticket/5738 .具体来说,马尔科姆对#5738的评论在以下部分给出:

There are a few Django tickets relevant to this issue https://code.djangoproject.com/ticket/16541 and https://code.djangoproject.com/ticket/5738. In particular Malcolm's comment on #5738 given in part below:

问题是,尽管强烈建议将UTF-8作为非ASCII数据的编码,实际上在任何规范中都没有进行编码直到最近(例如RFC 2396仍使事情大为开放).只有在RFC 3986中,IRI到URI编码才清楚.

The problem is that although UTF-8 is strongly recommended as the encoding for non-ASCII data, it's not actually codified in any spec until quite recently (RFC 2396 leaves things wide open, for example). Only in RFC 3986 were things made clear for IRI to URI encoding.

在此期间,部署了吐出非UTF-8编码的系统URI.

In the interim, systems were deployed that spit out non-UTF-8 encoded URIs.

所以我要提交一个更改,该更改会传回400的响应格式错误的输入(非UTF-8),但也更容易覆盖请求类,因此,如果有人正在处理遗留系统,他们可以将WSGIRequestor或ModPythonRequest子类化以处理解码URI,但是他们需要.

So I'm going to commit a change that passes back a 400 response for malformed input (non-UTF-8) but also makes it easier to override the request class, so if somebody is dealing with a legacy system, they can subclass WSGIRequestor or ModPythonRequest to handle decoding the URI however they need to.

这篇关于Django不能在网址中加引号字符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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