问题1:ImportError: No module named markup
django.utils.markup在1.5中声明被废弃,在1.6中被删除。
解决办法是:
-
安装docutils
pip install docutils
参考:http://stackoverflow.com/questions/20055603/how-can-i-satisfy-a-django-contrib-markup-templatetags-markup-import-restructure
-
在模板中将无法使用markdown,也就是无法使用 {% load markup %} 。
问题出现为:load markup deprecated
请使用 register.filter 引入 template tag来在模板中解决。
如:
import markdown2
.. all other imports needed..
register = template.Library()
@register.filter(is_safe=True)
@stringfilter
def markdown2(value):
return mark_safe(markdown2.markdown(force_unicode(value),safe_mode=True,enable_attributes=False))
然后在你的模板中使用:
{% load myapp_markup %}
{{ value|markdown2 }}
参考:
1. http://stackoverflow.com/questions/1383826/importerror-for-django-contrib-markup
2. http://stackoverflow.com/questions/16689334/django-1-5-markdown-deprecation
问题2:ImportError: No module named hashcompat
hashcompat 已经被废弃了,请使用
from hashlib import sha1 as sha_constructor
参考:http://stackoverflow.com/questions/16463842/python-django-importerror-no-module-named-hashcompat
问题3:truncate_words被废弃
解决:请使用以下代码替换 from django.utils.text import truncate_words
try:
from django.utils.text import truncate_words
except ImportError:
# Django >=1.5
from django.utils.text import Truncator
from django.utils.functional import allow_lazy
def truncate_words(s, num, end_text = '...'):
truncate = end_text and ' %s' % end_text or ''
return Truncator(s).words(num, truncate = truncate)
truncate_words = allow_lazy(truncate_words, unicode)
参考:
- https://docs.djangoproject.com/en/1.5/internals/deprecation/#id3
- https://github.com/divio/djangocms-text-ckeditor/pull/70
问题4:ImportError: No module named simple
问题:from django.views.generic.simple import redirect_to 已经被废弃
解决:请使用:
from django.views.generic import RedirectView
urlpatterns = patterns('',
(r'^one/$', RedirectView.as_view(url='/another/')),
)
参考:http://stackoverflow.com/questions/11428427/no-module-named-simple-error-in-django
问题5:ImportError: No module named defaults
django.conf.urls.defaults 已经被废弃,请使用:
from django.conf.urls import patterns, url, include
参考:http://stackoverflow.com/questions/19962736/django-import-error-no-module-named-django-conf-urls-defaults
问题6:ImportError: cannot import name list_detail
请使用
from django.views.generic.list import ListView
ListView.as_view(request, qs, **kwargs)
参考:
- http://www.douban.com/group/topic/41823683/
- http://stackoverflow.com/questions/15624509/whats-current-django-for-from-django-views-generic-import-list-detail
问题7:'url' requires a non-empty first argument
这个可能是这次版本升级最大的更新点,影响范围非常之大。。
你需要将所有类似下面的代码
{% url registration_activate activation_key %}
更新为:
{% url 'registration_activate' activation_key %}
易冷天涯整理了一个Sed脚本用来全局替换
http://www.dkjiaoyang.com/2/post/2013/04/url-requires-a-non-empty-first-argument.html
有兴趣的同学可以参考下
问题8:from django.core.validators import email_re
请使用以下代码进行替换:
try:
from django.forms.fields import email_re
except ImportError:
from django.core.validators import email_re
问题9:Django-nonrel + Django-registration problem: unexpected keyword argument 'uidb36' when resetting password
Django 1.6 使用了64位的编码方法,所以,你需要将
url(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
'django.contrib.auth.views.password_reset_confirm',
name='password_reset_confirm'),
变更为:
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
'django.contrib.auth.views.password_reset_confirm',
name='password_reset_confirm'),
另外,很可能你需要兼容旧数据,因此,你的代码应该变更为:
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
'django.contrib.auth.views.password_reset_confirm',
name='password_reset_confirm_uidb36'),
url(r'^reset/(?P<uidb32>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
'django.contrib.auth.views.password_reset_confirm''),
参考:
- http://stackoverflow.com/questions/6323852/django-nonrel-django-registration-problem-unexpected-keyword-argument-uidb36
- https://docs.djangoproject.com/en/1.6/releases/1.6/#django-contrib-auth-password-reset-uses-base-64-encoding-of-user-pk
问题10:ALLOWED_HOSTS
Django1.6在debug=False情况下,需要使用ALLOWED_HOSTS
参考:https://docs.djangoproject.com/en/1.5/ref/settings/