Skip to content

Commit

Permalink
Authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfreire committed Oct 23, 2019
1 parent c1ab581 commit 5193a66
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.shortcuts import render

# third party imports
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView

Expand All @@ -10,6 +11,9 @@


class TestView(APIView):

permission_classes = (IsAuthenticated, )

def get(self, request, *args, **kwargs):
qs = Post.objects.all()
post = qs.first()
Expand Down
Binary file modified db.sqlite3
Binary file not shown.
8 changes: 8 additions & 0 deletions drf_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'core'
]

Expand Down Expand Up @@ -120,3 +122,9 @@
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication'
]
}
5 changes: 4 additions & 1 deletion drf_api/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from django.contrib import admin
from django.urls import path, include
from rest_framework.authtoken.views import obtain_auth_token

from core.views import TestView

urlpatterns = [
path('api-auth/', include('rest_framework.urls')),
path('rest-auth/', include('rest_auth.urls')),
path('admin/', admin.site.urls),
path('', TestView.as_view(), name='test')
path('', TestView.as_view(), name='test'),
path('api/token/', obtain_auth_token, name='obtain-token')
]
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Django==2.2.6
django-rest-auth==0.9.5
djangorestframework==3.10.3
pytz==2019.3
six==1.12.0
sqlparse==0.3.0

0 comments on commit 5193a66

Please sign in to comment.