Skip to content

Commit

Permalink
setting jwt
Browse files Browse the repository at this point in the history
  • Loading branch information
shing100 committed Aug 26, 2018
1 parent 195817d commit ca33240
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,31 @@ king = Owner.objects.get(pk=1)
king_cats = king.cat_set.all()
```

## Setting up JWT
http://getblimp.github.io/django-rest-framework-jwt/

pip install djangorestframework-jwt
설치 후 settings.py 에 더하기 쿠키커터의 경우 base.py

```python
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
}

# 그리고 url.py에 추가하여 사용
from rest_framework_jwt.views import obtain_jwt_token
url(r'^api-token-auth/', obtain_jwt_token),
or
path("api-token-auth", obtain_jwt_token),
```

## 기본적인 모델 생성방법
```python
class TimeStampedModel(models.Model):
Expand Down
12 changes: 12 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,15 @@
# ------------------------------------------------------------------------------
# 해시태그 설정 django-taggit
TAGGIT_CASE_INSENSITIVE = True


REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
}
8 changes: 2 additions & 6 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@
from django.contrib import admin
from django.views.generic import TemplateView
from django.views import defaults as default_views
from rest_framework_jwt.views import obtain_jwt_token

urlpatterns = [
path("", TemplateView.as_view(template_name="pages/home.html"), name="home"),
path(
"about/",
TemplateView.as_view(template_name="pages/about.html"),
name="about",
),
# Django Admin, use {% url 'admin:index' %}
path(settings.ADMIN_URL, admin.site.urls),
path("api-token-auth", obtain_jwt_token),
# User management
path(
"users/",
Expand Down
4 changes: 2 additions & 2 deletions limstagram/images/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
urlpatterns = [
path("", view=views.Feed.as_view(), name="feed"),
path("<int:image_id>", view=views.ImageDetail.as_view(), name="feed"),
path("<int:image_id>/likes/", view=views.LikeImage.as_view(), name="like_image"),
path("<int:image_id>/unlikes/", view=views.unLikeImage.as_view(), name="unlike_image"),
path("<int:image_id>/likes", view=views.LikeImage.as_view(), name="like_image"),
path("<int:image_id>/unlikes", view=views.unLikeImage.as_view(), name="unlike_image"),
path("<int:image_id>/comments", view=views.CommentOnImage.as_view(), name="commnet_image"),
path("<int:image_id>/comments/<int:comment_id>", view=views.ModerateComments.as_view(), name="commnet_image"),
path("comments/<int:comment_id>", view=views.Comment.as_view(), name="comment"),
Expand Down
2 changes: 1 addition & 1 deletion limstagram/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
path("<str:username>/followers", view=views.UserFollowers.as_view(), name='user_followers'),
path("<str:username>/following", view=views.UserFollowing.as_view(), name='user_following'),
path("search", view=views.Search.as_view(), name='search'), # 순서 중요함
path("<str:username>/", view=views.UserProfile.as_view(), name="user_profile"),
path("<str:username>", view=views.UserProfile.as_view(), name="user_profile"),
path("<str:username>/password", view=views.ChangePassword.as_view(), name="change")
]

0 comments on commit ca33240

Please sign in to comment.