getting type error at /. It may be too localized but I have been racking my brain and searching the web for an answer with no luck. Thank you in advance for your help
TypeError at /
'function' object has no attribute '__getitem__'
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.8.3
Exception Type: TypeError
Exception Value:
'function' object has no attribute '__getitem__'
Exception Location: /Users/wrb473/Documents/workspace/angulardjango/angulardjango/urls.py in <module>, line 22
Python Executable: /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Python Version: 2.7.10
url.py
from django.conf.urls import patterns, include, url
from rest_framework.routers import DefaultRouter
#from rest_framework import routers
from django.contrib import admin
from django.contrib.auth.models import User
from rest_framework import routers,serializers,viewsets
from tweeter import views
admin.autodiscover()
router = DefaultRouter()
router = routers.SimpleRouter()
router.register(r'tweets', views.TweetViewSet,base_name='tweets')
router.register(r'users', views.UserViewSet,base_name='users')
urlpatterns = patterns['',
url(r'^admin/', include(admin.site.urls)),
url(r'^api/', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^$', views.index, name='index'),
]
here is my views. views.py
from django.shortcuts import render
from django.contrib.auth import authenticate, login
from django.contrib.auth.models import User
from django.views.decorators.csrf import csrf_protect, ensure_csrf_cookie
from rest_framework import permissions, viewsets
from tweeter.models import Tweet
from tweeter.permissions import IsAuthorOrReadOnly
from tweeter.serializers import TweetSerializer, UserSerializer
@csrf_protect
@ensure_csrf_cookie
def index(request):
user = authenticate(username='bob', password='bob')
if user is not None:
login(request, user)
return render(request, 'tweeter/index.html')
class TweetViewSet(viewsets.ModelViewSet):
queryset = Tweet.objects.all()
serializer_class = TweetSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,
IsAuthorOrReadOnly,)
def pre_save(self, obj):
obj.user = self.request.user
class UserViewSet(viewsets.ReadOnlyModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
Please help.
@csrf_protect,@ensure_csrf_cookie)indexor throw an http exception.