CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
from rest_framework.throttling import UserRateThrottle
class BurstRateThrottle(UserRateThrottle):
"""Allow short bursts of requests."""
scope = 'burst'
from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
class Comment(models.Model):
from django.core.cache import cache
from django.views.decorators.cache import cache_page
from django.utils.decorators import method_decorator
from django.views.generic import ListView, DetailView
from .models import Post
INSTALLED_APPS += ['silk']
MIDDLEWARE += ['silk.middleware.SilkyMiddleware']
# Silk configuration
SILKY_PYTHON_PROFILER = True
from django.core.mail import EmailMessage, EmailMultiAlternatives
from django.template.loader import render_to_string
from django.conf import settings
import os
CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': 'redis://127.0.0.1:6379/1',
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
import json
from channels.generic.websocket import AsyncWebsocketConsumer
class ChatConsumer(AsyncWebsocketConsumer):
async def connect(self):
from django.core.exceptions import ValidationError
def validate_file_size(file):
"""Limit file size to 5MB."""
max_size_mb = 5
from rest_framework import routers
from rest_framework_nested import routers as nested_routers
from . import views
router = routers.DefaultRouter()
router.register(r'posts', views.PostViewSet, basename='post')
import os
from .base import *
DEBUG = False
SECRET_KEY = os.environ['SECRET_KEY']
import random
class PrimaryReplicaRouter:
"""Route reads to replicas, writes to primary."""