Django1.5升级到1.11.15问题记录
1,url
django1.5中使用的是如下代码:
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^accounts/', include('seahub.base.registration_urls')),
url(r'^robots\.txt$', TemplateView.as_view(template_name='robots.txt',
content_type='text/plain')),
在Django1.11版本中,patterns方法已经被移除了,换成url即可:
from django.conf.urls import url
urlpatterns =[
(r'^accounts/','seahub.base.registration_urls'),
url(r'^robots\.txt$', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')),]
2,报AppRegistryNotReady(“Apps aren’t loaded yet.”),如下错误,错误原因是因为contacts/__init__.py
,contacts/models.py
,contacts/models.py
这三个文件相互引用了。
File "/data/i2share/i2share-server/seahub/seahub/contacts/__init__.py", line 2, in <module>
from handlers import *
File "/data/i2share/i2share-server/seahub/seahub/contacts/handlers.py", line 2, in <module>
from models import Contact
File "/data/i2share/i2share-server/seahub/seahub/contacts/models.py", line 45, in <module>
class Contact(models.Model):
File "/usr/lib64/python2.7/site-packages/django/db/models/base.py", line 105, in __new__
app_config = apps.get_containing_app_config(module)
File "/usr/lib64/python2.7/site-packages/django/apps/registry.py", line 237, in get_containing_app_config
self.check_apps_ready()
File "/usr/lib64/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
3,报错有关DefaultCacheProxy,原因:django1.11 中获取cache方式改变
解决方法:
from django.core.cache import cache
local_cache = cache(u'local')
改为
from django.core.cache import cache, caches
local_cache = caches['local']
使用方法相应改为
def get_dirents_cache_by_path(repo_id, commit_id, path, sort_flag=ORDER_BY_DEFAULT):
- local_cache = get_cache(u'local')
+ local_cache = caches['local']
cache_key_sorted = b64encode(u'dirents_%d_%s_%s_%s' % (sort_flag, repo_id, commit_id, path))
entries = local_cache.get(cache_key_sorted, [])
4, 报错:Model class django.contrib.sites.models.Site doesn’t declare an explicit app_label and isn’t in an application in INSTALLED_APPS
RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS
解决方法:将'django.contrib.sites'
加到INSTALLED_APPS中。
INSTALLED_APPS = (
'django.contrib.sites',
)