add cache and django debug toolbar

This commit is contained in:
David 2019-05-26 14:14:47 +08:00
parent ef945d02ff
commit 9601530a85
4 changed files with 91 additions and 9 deletions

View File

@ -45,7 +45,13 @@ INSTALLED_APPS = [
'utils',
]
if DEBUG:
INSTALLED_APPS += [
'debug_toolbar'
]
MIDDLEWARE = [
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
@ -55,6 +61,13 @@ MIDDLEWARE = [
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
if DEBUG:
MIDDLEWARE += [
'debug_toolbar.middleware.DebugToolbarMiddleware'
]
MIDDLEWARE += ['django.middleware.cache.FetchFromCacheMiddleware']
ROOT_URLCONF = 'BookingService.urls'
AUTH_USER_MODEL = 'user.User'
@ -96,6 +109,22 @@ DATABASES = {
}
}
# CACHE
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache'
}
} if DEBUG else {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': 'bookingservice_memcached:11211',
'TIMEOUT': 60,
}
}
CACHE_MIDDLEWARE_SECONDS = 60
# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
@ -180,3 +209,9 @@ if not DEBUG:
SESSION_COOKIE_SAMESITE = None
CSRF_COOKIE_SAMESITE = None
# Django Debug Toolbar
if DEBUG:
# DEBUG_TOOLBAR_PATCH_SETTINGS = False
INTERNAL_IPS = ('127.0.0.1', 'localhost')

View File

@ -13,11 +13,11 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.contrib import admin
from django.urls import path, include, re_path
from django.views.generic.base import TemplateView
from django.views.static import serve
from . import settings
from utils.views import UploadFileAPI
@ -30,3 +30,9 @@ urlpatterns = [
path('api/booking/', include('booking.urls', namespace='booking')),
path('api/file/', UploadFileAPI.as_view())
]
if settings.DEBUG:
import debug_toolbar
urlpatterns += [
path('debug/', include(debug_toolbar.urls)),
]

View File

@ -4,6 +4,7 @@ url = "https://pypi.tuna.tsinghua.edu.cn/simple"
verify_ssl = true
[dev-packages]
django-debug-toolbar = "*"
[packages]
django = "*"
@ -13,6 +14,7 @@ flower = "*"
celery = "*"
eventlet = "*"
psycopg2 = "*"
python-memcached = "*"
[requires]
python_version = "3.7"

55
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "d4ed3f93f7138a3827f3b5461a31c868bd6f1bb187168837bd3319df74611876"
"sha256": "f5e0c38bf5a4c12520573fccc9fd57bd36112da57038e5456845fc259c1fef91"
},
"pipfile-spec": 6,
"requires": {
@ -62,11 +62,11 @@
},
"djangorestframework": {
"hashes": [
"sha256:1d22971a5fc98becdbbad9710ca2a9148dd339f6cbea4c3ddbed2cb84bab94e1",
"sha256:2884763160b997073ff1e937bd820a69d23978902a3ccd0ba53a217e196239f0"
"sha256:376f4b50340a46c15ae15ddd0c853085f4e66058f97e4dbe7d43ed62f5e60651",
"sha256:c12869cfd83c33d579b17b3cb28a2ae7322a53c3ce85580c2a2ebe4e3f56c4fb"
],
"index": "pypi",
"version": "==3.9.3"
"version": "==3.9.4"
},
"dnspython": {
"hashes": [
@ -77,11 +77,11 @@
},
"eventlet": {
"hashes": [
"sha256:c584163e006e613707e224552fafc63e4e0aa31d7de0ab18b481ac0b385254c8",
"sha256:d9d31a3c8dbcedbcce5859a919956d934685b17323fc80e1077cb344a2ffa68d"
"sha256:62b9d7581229c5195c3411dd30d15dea351daa5ee37e45a1329ee56fac0e4ef4",
"sha256:f0610bd0d3bb3d51d69f74caa4ad04fc7bce424cdb72e54d08ccda90d8c69800"
],
"index": "pypi",
"version": "==0.24.1"
"version": "==0.25.0"
},
"flower": {
"hashes": [
@ -145,6 +145,14 @@
"index": "pypi",
"version": "==2.8.2"
},
"python-memcached": {
"hashes": [
"sha256:4dac64916871bd3550263323fc2ce18e1e439080a2d5670c594cf3118d99b594",
"sha256:a2e28637be13ee0bf1a8b6843e7490f9456fd3f2a4cb60471733c7b5d5557e4f"
],
"index": "pypi",
"version": "==1.59"
},
"pytz": {
"hashes": [
"sha256:303879e36b721603cc54604edcac9d20401bdbe31e1e4fdee5b9f98d5d31dfda",
@ -186,5 +194,36 @@
"version": "==1.3.0"
}
},
"develop": {}
"develop": {
"django": {
"hashes": [
"sha256:6fcc3cbd55b16f9a01f37de8bcbe286e0ea22e87096557f1511051780338eaea",
"sha256:bb407d0bb46395ca1241f829f5bd03f7e482f97f7d1936e26e98dacb201ed4ec"
],
"index": "pypi",
"version": "==2.2.1"
},
"django-debug-toolbar": {
"hashes": [
"sha256:89d75b60c65db363fb24688d977e5fbf0e73386c67acf562d278402a10fc3736",
"sha256:c2b0134119a624f4ac9398b44f8e28a01c7686ac350a12a74793f3dd57a9eea0"
],
"index": "pypi",
"version": "==1.11"
},
"pytz": {
"hashes": [
"sha256:303879e36b721603cc54604edcac9d20401bdbe31e1e4fdee5b9f98d5d31dfda",
"sha256:d747dd3d23d77ef44c6a3526e274af6efeb0a6f1afd5a69ba4d5be4098c8e141"
],
"version": "==2019.1"
},
"sqlparse": {
"hashes": [
"sha256:40afe6b8d4b1117e7dff5504d7a8ce07d9a1b15aeeade8a2d10f130a834f8177",
"sha256:7c3dca29c022744e95b547e867cee89f4fce4373f3549ccd8797d8eb52cdb873"
],
"version": "==0.3.0"
}
}
}