Django1.5升级到1.11.15问题记录

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__.pycontacts/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',
)
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值