Django1.7升级到Django1.9一些点

1、在urls.py里,不要直接用字符串来描述方法、要用引用来配置(越来越向OOP看齐?),比如,再这么配置的话,

 url(r'^$', 'portal.views.index', {'template_name': 'index.html'}, name='index'),

会得到一个警告:

RemovedInDjango110Warning: Support for string view arguments to url() is deprecated and will be removed in Django 1.10 (got portal.views.index). Pass the callable instead.
  url(r'^$', 'portal.views.index', {'template_name': 'index.html'}, name='index'),

应该改为:

from portal.views import index
...
url(r'^$', index, {'template_name': 'index.html'}, name='index'),
...

2、render_to_response的这种形式也会得到过时的警告:

return render_to_response(template_name,
                              template_var,
                              context_instance=RequestContext(request))

应该改为:

from django.shortcuts import render
...
from django.shortcuts import render
...
return render(request, template_name, template_var)

回头再添加。。。

Django1.9 升级
阅读(3248) 评论(2) 2016-01-26
小白 :
意外发现,前来学习
老楠 回复 小白 :
共同学习。
输入类似这样的地址 "name@something.com"
输入类似这样的地址"http://someaddress.com"
验证码 不区分大小写(看不清)