我是Python和Django的初学者。在
我正在建立一个在本地编写的程序。在几乎完成了让应用程序在服务器上运行之后,我了解到服务器运行的是python2.6,而我的本地系统运行的是2.7。这似乎给了我从url检索参数时的问题。在
我用的是Openshift的服务器。我不太了解服务器,但我目前的设置是,我有一个本地克隆的文件,我在本地处理一切,并通过git将它们推送到服务器。服务器是使用Openshift界面中预定义的快速设置来设置的。在
我使用下面的urlpattern,它在我的计算机上本地运行得很好。在
url(r'^website/(?P<url>[:\w/\-.]+)$', 'page'),
但是,在我的服务器版本上,我遇到了一些问题。下面的url返回两个不同的url到视图,这取决于我是在服务器上还是在本地运行。在
^{pr2}$在我看来,反斜杠在某处被砍掉了。如何更改它来解析带有两个反斜杠的参数?在
# the receiving view
def page(request, url):
p = Page.objects.get(url=url)
domain = p.website.url
return render_to_response('seo/page.html', {'domain': domain, 'page': p}, context_instance=RequestContext(request))
本地版本返回的页面很好。服务器版本将返回:
DoesNotExist at /website/http:/coverme.dk/collections/iphone-sleeves-covers
我注意到http://中的一个反斜杠在这里丢失了,并假定错误是基于它被错误地发送到视图的。在
我刚刚用本地版本的数据库中不存在的url进行了测试,它正确地显示了错误消息。在
我还仔细检查了url='http://coverme.dk/collections/iphone-sleeves-covers'的对象是否确实存在。我也和其他几个人核实过了。在
我已经尝试过在输入url上乱搞,它似乎工作得很好,除非我使用两倍、三倍的反斜杠。url中第一个之后的所有反斜杠都将被忽略。在
/website/http://////coverme.dk////collections/iphone-sleeves-covers
#gives the same as
/website/http:/coverme.dk/collections/iphone-sleeves-covers.
任何形式的帮助都是非常感谢的。一个链接到一些文件,可以帮助我将不胜感激。在
编辑:更新django解决了这个问题。在
来自a comment的问题作者:
相关问题 更多 >
编程相关推荐