Commit e6d0503b authored by John Kirkwood's avatar John Kirkwood

Add debug_toolbar

parent 1ffce1c3
from django.urls import path
from django.urls import path, reverse_lazy
from django.views import generic
from . import views
app_name = 'blog'
urlpatterns = [
path('',
generic.RedirectView.as_view(url=reverse_lazy('blog:post_create')),
name='default'),
path('post/create',
views.PostCreateView.as_view(), name='post_create'),
path('post/<int:pk>/',
......
import os
# FORM_RENDERER = 'chp.django.mdc.renderer.FormRenderer'
SECRET_KEY = os.getenv('SECRET_KEY', 'notsecret')
......@@ -12,12 +13,19 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'debug_toolbar',
'chp.django', # management command
'chp.django.example.blog',
'chp.django.example.todos',
'crudlfap',
# 'chp.django.example.todos',
# 'crudlfap',
]
ALLOWED_HOSTS = ['*']
ALLOWED_HOSTS = []
if DEBUG:
ALLOWED_HOSTS = ['*']
if 'debug_toolbar' in INSTALLED_APPS:
from .utils import IP_List
INTERNAL_IPS = IP_List('127.0.0.1', '192.168.1.0/24')
STATIC_URL = '/static/'
BASE_DIR = os.path.dirname(__file__)
STATICFILES_DIRS = [
......@@ -31,6 +39,7 @@ DATABASES = {
}
MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
......@@ -56,3 +65,4 @@ TEMPLATES = [
},
]
TIME_ZONE = "Europe/London"
from django.conf import settings
from django.contrib import admin
from django.urls import include, path, reverse_lazy, re_path
from django.views import generic
from django.urls import include, path
urlpatterns = [
path('', generic.RedirectView.as_view(url='/blog/post/create')),
path('', generic.RedirectView.as_view(url=reverse_lazy('blog:default'))),
path('blog/', include('chp.django.example.blog.urls',
namespace='blog')),
path('todos/', include('chp.django.example.todos.urls',
namespace='todos')),
path('admin/', admin.site.urls),
]
if 'debug_toolbar' in settings.INSTALLED_APPS and settings.DEBUG:
import debug_toolbar
urlpatterns = [
path('__debug__/', include(debug_toolbar.urls)),
] + urlpatterns
from collections import UserList
from ipaddress import IPv4Address, IPv4Network
class IP_List(UserList):
""" A list of IP networks that can be used for comparison.
This class allows an IP address to be checked against a list of
networks for Django's INTERNAL_IPS setting. (Django only
ever needs to do "ip in INTERNAL_IPS" so `contains` is sufficient for
this purpose.)
For example, to make localhost and the entire block of 192.168.1.*
considered to be internal, use::
INTERNAL_IPS = IP_List(['127.0.0.1', '192.168.1.0/24'])
"""
def __init__(self, *args):
super().__init__([IPv4Network(arg) for arg in args])
def __contains__(self, ip):
ip = IPv4Address(ip)
return any([(ip in addr) for addr in self])
def __len__(self):
return super().__len__()
def __getitem__(self, i):
return super().__getitem__(i)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment