使用djangorestframework 0.3.0和django 1.7

时间:2015-11-19 11:03:46

标签: python django django-rest-framework

我将django和我使用的所有应用程序升级到最新版本,但由于djangorestframework 0.4.0和3.3.0之间的巨大变化,我已经回到0.4.0并选择修复它导入的更简单的问题来自django.utils的json并将其编辑为import json现在我收到错误templatedoesnotexist

Environment:


Request Method: GET
Request URL: http://kbuzz.webfactional.com/rest/movies/?device=browser

Django Version: 1.7.10
Python Version: 2.7.9
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.sitemaps',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.redirects',
 'django.contrib.humanize',
 'autocomplete_light',
 'rest_framework',
 'haystack',
 'lamusoftware.generic',
 'mptt',
 'bootstrapform',
 'sorl.thumbnail',
 'oauth2client',
 'articles',
 'banners',
 'common',
 'directory',
 'events',
 'galleries',
 'marketplace',
 'movies',
 'pages',
 'profiles',
 'search',
 'stats',
 'minidetector',
 'mobile',
 'reports',
 'favorites',
 'braces',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'allauth.socialaccount.providers.facebook',
 'widget_tweaks',
 'wordofmouth',
 'ckeditor',
 'django_mobile',
 'debug_toolbar',
 'markup_deprecated')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
 'minidetector.Middleware',
 'mobileesp.middleware.MobileDetectionMiddleware',
 'kb.middleware.log_ip_middleware.SetRemoteAddrFromForwardedFor',
 'kb.middleware.log_ip_middleware.RedirectMovie')

Template Loader Error:
Django tried loading these templates, in this order:
Using loader django_mobile.loader.Loader:
Using loader django.template.loaders.filesystem.Loader:
/home/kbuzz/webapps/kenyabuzz/kb/kb/templates/djangorestframework/api.html (File does not exist)
Using loader django.template.loaders.app_directories.Loader:
/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/contrib/auth/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/contrib/sitemaps/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/contrib/admin/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/django/lib/python2.7/autocomplete_light/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/django/lib/python2.7/rest_framework/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/lib/python2.7/haystack/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/django/lib/python2.7/mptt/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/lib/python2.7/bootstrapform/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/kenyabuzz/kb/reports/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/kenyabuzz/kb/favorites/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/django/lib/python2.7/allauth/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/django/lib/python2.7/allauth/socialaccount/providers/facebook/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/kenyabuzz/kb/wordofmouth/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/lib/python2.7/ckeditor/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/django/lib/python2.7/debug_toolbar/templates/djangorestframework/api.html (File does not exist)



Traceback:
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/core/handlers/base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/views/generic/base.py" in view
  69.             return self.dispatch(request, *args, **kwargs)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/views/decorators/csrf.py" in wrapped_view
  57.         return view_func(*args, **kwargs)
File "/home/kbuzz/lib/python2.7/djangorestframework/views.py" in dispatch
  246.         return self.final(request, response, *args, **kwargs)
File "/home/kbuzz/lib/python2.7/djangorestframework/views.py" in final
  199.         return self.render(response)
File "/home/kbuzz/lib/python2.7/djangorestframework/mixins.py" in render
  251.             content = renderer.render(response.cleaned_content, media_type)
File "/home/kbuzz/lib/python2.7/djangorestframework/renderers.py" in render
  342.         template = loader.get_template(self.template)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/template/loader.py" in get_template
  144.     template, origin = find_template(template_name, dirs)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/template/loader.py" in find_template
  136.     raise TemplateDoesNotExist(name)

Exception Type: TemplateDoesNotExist at /rest/movies/
Exception Value: djangorestframework/api.html

更新

我已将rest_framework的设置文件编辑为djangorestframework,现在获取此错误的mimetype必须已针对httpresponse删除。

环境:

Request Method: GET
Request URL: http://kbuzz.webfactional.com/rest/movies/categories/?device=browser

Django Version: 1.7.10
Python Version: 2.7.9
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.sitemaps',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.redirects',
 'django.contrib.humanize',
 'autocomplete_light',
 'djangorestframework',
 'haystack',
 'lamusoftware.generic',
 'mptt',
 'bootstrapform',
 'sorl.thumbnail',
 'oauth2client',
 'articles',
 'banners',
 'common',
 'directory',
 'events',
 'galleries',
 'marketplace',
 'movies',
 'pages',
 'profiles',
 'search',
 'stats',
 'minidetector',
 'mobile',
 'reports',
 'favorites',
 'braces',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'allauth.socialaccount.providers.facebook',
 'widget_tweaks',
 'wordofmouth',
 'ckeditor',
 'django_mobile',
 'debug_toolbar',
 'markup_deprecated')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
 'minidetector.Middleware',
 'mobileesp.middleware.MobileDetectionMiddleware',
 'kb.middleware.log_ip_middleware.SetRemoteAddrFromForwardedFor',
 'kb.middleware.log_ip_middleware.RedirectMovie')


Traceback:
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/core/handlers/base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/views/generic/base.py" in view
  69.             return self.dispatch(request, *args, **kwargs)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/views/decorators/csrf.py" in wrapped_view
  57.         return view_func(*args, **kwargs)
File "/home/kbuzz/lib/python2.7/djangorestframework/views.py" in dispatch
  246.         return self.final(request, response, *args, **kwargs)
File "/home/kbuzz/lib/python2.7/djangorestframework/views.py" in final
  199.         return self.render(response)
File "/home/kbuzz/lib/python2.7/djangorestframework/mixins.py" in render
  256.         resp = HttpResponse(content, mimetype=response.media_type, status=response.status)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/http/response.py" in __init__
  318.         super(HttpResponse, self).__init__(*args, **kwargs)

Exception Type: TypeError at /rest/movies/categories/
Exception Value: __init__() got an unexpected keyword argument 'mimetype'

1 个答案:

答案 0 :(得分:1)

如果您已切换回休息框架0.4.0,则应将INSTALLED_APPS中的值从rest_framework更改回djangorestframework

然后app模板加载器应该在djangorestframework/templates目录中找到模板。