python - 使用 djangorestframework 0.3.0 和 django 1.7

标签 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'

最佳答案

如果您已切换回 Rest framwork 0.4.0,则应将 INSTALLED_APPS 中的值从 rest_framework 更改回 djangorestframework

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

关于python - 使用 djangorestframework 0.3.0 和 django 1.7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33802101/

相关文章:

python - Bottle 模板

python - 解析错误

python - 如何制作字段名称与模型字段名称不同的 Django 模型表单?

jquery - django-autocomplete-light : "The results could not be loaded"

python - DRF 响应内容类型在测试期间设置为无

python - Django Rest 框架 ImageField

Python:初始化时@property装饰器无限循环?

python - 如何根据给定条件交换字符串的字符?

Django 模型继承创建或从父级获取

django - 如果模型中已存在相同的数据,如何停止 Post 请求