Django Rest API urlsplit error
我尝试使用django rest设置API,我尝试使用快速入门指南,但我只能得到以下错误:
我在网上找不到任何关于这个错误的参考,更不用说如何解决它了。
这是我的URL文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | from django.conf.urls import patterns, include, url from django.contrib.auth.models import User from django.contrib import admin from rest_framework import routers, serializers, viewsets admin.autodiscover() class UserSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = User fields = ('url', 'username', 'email', 'is_staff') class UserViewSet(viewsets.ModelViewSet): queryset = User.objects.all() serializer_class = UserSerializer router = routers.DefaultRouter() router.register(r'users', UserViewSet) urlpatterns = patterns('', url(r'^', include(router.urls)), url(r'^', include('logs.urls')), url(r'^admin/', include(admin.site.urls)), url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')), ) |
完全回溯:
Environment:
Request Method: GET
Django Version: 1.6 Python Version: 2.7.6 Installed Applications:
('rest_framework', 'south', 'django.contrib.admin',
'django.contrib.admindocs', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.staticfiles', 'logs',
'django_nose') Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')Template error: In template
/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/rest_framework/templates/rest_framework/base.html,
error at line 87 'Module_six_moves_urllib_parse' object has no
attribute 'urlsplit' 77 :
rel="nofollow" title="Make a GET request on the {{ name }}
resource">GET78 :
79 :
80 : title="Specify a
format for the GET request">81 :
82 :
83 :
84 : {% for format in
available_formats %}85 :
86 :
87 : href=' {%
add_query_param request api_settings.URL_FORMAT_OVERRIDE format %} '88 :
rel="nofollow"89 : title="Make a
GET request on the {{ name }} resource with the format set to{{ ">
format }}90 : {{ format }}
91 :
92 :
93 : {% endfor %}
94 :
95 :
96 :
97 :
Traceback: File
"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/core/handlers/base.py"
in get_response
139. response = response.render() File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/template/response.py"
in render
105. self.content = self.rendered_content File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/rest_framework/response.py"
in rendered_content
59. ret = renderer.render(self.data, media_type, context) File
"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/rest_framework/renderers.py"
in render
733. ret = template.render(context) File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/template/base.py"
in render
140. return self._render(context) File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/template/base.py"
in _render
134. return self.nodelist.render(context) File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/template/base.py"
in render
840. bit = self.render_node(node, context) File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/template/debug.py"
in render_node
78. return node.render(context) File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/template/loader_tags.py"
in render
123. return compiled_parent._render(context) File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/template/base.py"
in _render
134. return self.nodelist.render(context) File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/template/base.py"
in render
840. bit = self.render_node(node, context) File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/template/debug.py"
in render_node
78. return node.render(context) File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/template/loader_tags.py"
in render
62. result = block.nodelist.render(context) File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/template/base.py"
in render
840. bit = self.render_node(node, context) File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/template/debug.py"
in render_node
78. return node.render(context) File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/template/defaulttags.py"
in render
305. return nodelist.render(context) File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/template/base.py"
in render
840. bit = self.render_node(node, context) File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/template/debug.py"
in render_node
78. return node.render(context) File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/template/defaulttags.py"
in render
196. nodelist.append(node.render(context)) File
"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/django/template/base.py"
in render
1125. return func(*resolved_args, **resolved_kwargs) File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/rest_framework/templatetags/rest_framework.py"
in add_query_param
86. return escape(replace_query_param(uri, key, val)) File"/Users/taylorhobbs/.virtualenvs/Workout_log/lib/python2.7/site-packages/rest_framework/templatetags/rest_framework.py"
in replace_query_param
22. (scheme, netloc, path, query, fragment) = urlparse.urlsplit(url)Exception Type: AttributeError at / Exception Value:
'Module_six_moves_urllib_parse' object has no attribute 'urlsplit'
号
尝试升级您的django版本。Base 1.6不具有此功能,但1.6.3具有此功能。https://docs.djangoproject.com/en/dev/releases/1.6.3/
所以我已经解决了我的问题,目前为止,我把我的DRF版本从3改为2.4,它似乎解决了我的问题。如果其他人有合法答案,请分享。
是的,这正是我犯的错误。我使用的是python 2.6,django 1.6。我试着换成DRF 2.4
P.S:当我在最新的DRF中使用python 3.4和django 1.7时。没有错误。P.S.S-删除了3.0.1并安装了2.4.4,然后将其添加到settings.py中。它起作用了。
1 2 3 4 | TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ) |