Slide 26
Slide 26 text
print 'hello world!'
3. Add some security cont…
from django.views.decorators.csrf import csrf_exempt
from django.contrib.admin.views.decorators import staff_member_required
from rest_framework.authtoken import views
from rest_framework.authentication import TokenAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.decorators import authentication_classes, permission_classes,
api_view
from graphene_django.views import GraphQLView
def graphql_token_view():
view = GraphQLView.as_view(schema=schema)
view = permission_classes((IsAuthenticated,))(view)
view = authentication_classes((TokenAuthentication,))(view)
view = api_view(['POST'])(view)
return view
urlpatterns = [
url(r'^graphql', graphql_token_view()),
url(r'^graphiql',
staff_member_required(csrf_exempt(GraphQLView.as_view(graphiql=True)))),
url(r'^api/auth/', include('rest_framework.urls',
namespace='rest_framework')),
url(r'^api/token-auth/', views.obtain_auth_token),
]
proj/urls.py
$ pip install django-rest-framework