added redis & django toolbar
This commit is contained in:
parent
0d64d090fa
commit
3564fcc360
3 changed files with 28 additions and 1 deletions
|
|
@ -4,10 +4,16 @@ from rest_framework.permissions import IsAuthenticated
|
|||
from rest_framework.response import Response
|
||||
from .serializer import VideoSerializer
|
||||
from .models import Video
|
||||
from django.core.cache.backends.base import DEFAULT_TIMEOUT
|
||||
from django.views.decorators.cache import cache_page
|
||||
from django.conf import settings
|
||||
|
||||
CACHETTL = getattr(settings, 'CACHE_TTL', DEFAULT_TIMEOUT)
|
||||
|
||||
# Create your views here.
|
||||
@api_view(['GET'])
|
||||
@permission_classes([IsAuthenticated])
|
||||
@cache_page(CACHETTL)
|
||||
def video_list(request):
|
||||
|
||||
if request.method == 'GET':
|
||||
|
|
|
|||
|
|
@ -51,11 +51,13 @@ INSTALLED_APPS = [
|
|||
'rest_framework.authtoken',
|
||||
'rest_framework',
|
||||
'corsheaders',
|
||||
'debug_toolbar',
|
||||
'content.apps.ContentConfig',
|
||||
'users',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'debug_toolbar.middleware.DebugToolbarMiddleware',
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
|
|
@ -84,6 +86,24 @@ TEMPLATES = [
|
|||
},
|
||||
]
|
||||
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django_redis.cache.RedisCache",
|
||||
"LOCATION": "redis://127.0.0.1:6379/1",
|
||||
"OPTIONS": {
|
||||
"PASSWORD": 'foobared',
|
||||
"CLIENT_CLASS": "django_redis.client.DefaultClient"
|
||||
},
|
||||
"KEY_PREFIX": "videoflix"
|
||||
}
|
||||
}
|
||||
|
||||
INTERNAL_IPS = [
|
||||
'127.0.0.1',
|
||||
]
|
||||
|
||||
CACHE_TTL = 60 * 15
|
||||
|
||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||
THUMBNAIL_DIR = os.path.join(BASE_DIR, 'media/img')
|
||||
MEDIA_URL = '/media/'
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ from auth.views import (
|
|||
ChangePasswordView
|
||||
)
|
||||
from content import views as content_views
|
||||
from debug_toolbar.toolbar import debug_toolbar_urls
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
|
|
@ -46,4 +47,4 @@ urlpatterns = [
|
|||
path('auth/verify-email/', VerifyEmailView.as_view()),
|
||||
path('auth/forgot-password/', ForgotPasswordView.as_view()),
|
||||
path('auth/change-password/', ChangePasswordView.as_view()),
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + debug_toolbar_urls()
|
||||
Loading…
Reference in a new issue