After finishing tutorial 1-3 smoothly, I followed the tutorial (http://django-rest-framework.org/tutorial/4-authentication-and-permissions.html) and finished sections up to "Adding endpoints for our User models".
(In other words, adding "url(r'^users/$', views.UserList.as_view()), url(r'^users/(?P[0-9]+)/$', views.UserInstance.as_view())," was done.)
Then, I ran the server with the command of "python manage.py runserver" and point my browser to http://127.0.0.1:8000/users/ and got the following error message:
(message starts)
NameError at /users/
name 'User' is not defined
Request Method: GET
Request URL: http://127.0.0.1:8000/users/
Django Version: 1.4.3
Exception Type: NameError
Exception Value: name 'User' is not defined
Exception Location: /home/user/tutorial/snippets/serializers.py in Meta, line 14
(message ends)
Did I miss something?
The code in my serializer.py was:
from django.forms import widgets
from rest_framework import serializers
from snippets import models
class SnippetSerializer(serializers.ModelSerializer):
class Meta:
model = models.Snippet
fields = ('id', 'title', 'code', 'linenos', 'language', 'style')
class UserSerializer(serializers.ModelSerializer):
snippets = serializers.ManyPrimaryKeyRelatedField()
class Meta:
model = User
fields = ('id', 'username', 'snippets')