xadmin引入django-debug-toolbar调试工具
一、安装:
pip install django-debug-toolbar
安装django-debug-toolbar库
https://github.com/jazzband/django-debug-toolbar
GitHub主页
二、设置demo/settings.py:
import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'db@02^k!pw$6kx*0$+9#%2h@vro-*h^+xs%5&(+q*b181&o$)l' # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'product.apps.ProductConfig', 'xadmin',
'crispy_forms',
'reversion',
# 添加django-xadmin 'import_export',
# 导入导出 'ckeditor',
'ckeditor_uploader',
# 富文本编辑器 'rest_framework',
# django-rest-framework 'drf_yasg',
# drf-yasg 'debug_toolbar',
# django-debug-toolbar
] MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware',
# 启用debug_toolbar中间件
] ROOT_URLCONF = 'demo.urls' TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
] WSGI_APPLICATION = 'demo.wsgi.application' # Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'demo',
'HOST': '192.168.1.106',
'PORT': '3306',
'USER': 'root',
'PASSWORD': 'Abcdef@123456',
}
}
# MySQL数据库配置 # Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
] # Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/ LANGUAGE_CODE = 'zh-hans'
# 简体中文界面 TIME_ZONE = 'Asia/Shanghai'
# 亚洲/上海时区 USE_I18N = True USE_L10N = True USE_TZ = False
# 不使用国际标准时间 # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/ STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# 定义静态文件的目录 MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# 定义图片存放的目录 IMPORT_EXPORT_USE_TRANSACTIONS = True
# 在导入数据时使用数据库事务,默认False CKEDITOR_BASEPATH = os.path.join(BASE_DIR, "/static/ckeditor/ckeditor/")
# 配置CKEditor的模板路径
CKEDITOR_CONFIGS = {
'default': {
'toolbar': 'full',
'height': 300,
'width': 900,
},
}
# 使用默认的主题名称
CKEDITOR_UPLOAD_PATH = "uploads/"
# 配置图片存储的目录,不用创建
# 默认使用MEDIA_ROOT,所以路径是media/uploads
CKEDITOR_RESTRICT_BY_DATE = True
# 按年/月/日的目录存储图片
CKEDITOR_BROWSE_SHOW_DIRS = True
# 按存储在其中的目录对图像进行分组,并按日期排序
CKEDITOR_IMAGE_BACKEND = "pillow"
# 启用缩略图 REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 5
# 分页
} INTERNAL_IPS = [
'127.0.0.1',
]
# 配置IP地址
三、复制静态资源文件:
python manage.py collectstatic
四、路由demo/urls.py:
import xadmin from django.conf import settings
from django.conf.urls import url
from django.conf.urls.static import static
from django.urls import path, include
from rest_framework import routers, permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi from product import views router = routers.DefaultRouter()
router.register('product_info', views.ProductInfoViewSet) schema_view = get_schema_view(
openapi.Info(
title="测试工程API",
default_version='v1.0',
description="测试工程接口文档",
terms_of_service="https://www.google.com/policies/terms/",
contact=openapi.Contact(email="contact@snippets.local"),
license=openapi.License(name="BSD License"),
),
public=True,
permission_classes=(permissions.AllowAny,),
) urlpatterns = [
path('admin/', xadmin.site.urls), path('ckeditor/', include('ckeditor_uploader.urls')),
# 添加CKEditor的URL映射 path('api/', include(router.urls)),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
# 配置django-rest-framwork API路由 url(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
path('swagger', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
# 配置drf-yasg路由
] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# 配置图片文件url转发 if settings.DEBUG:
import debug_toolbar
urlpatterns = [
path('__debug__/', include(debug_toolbar.urls)),
] + urlpatterns
五、调试页面:
python manage.py runserver
启动服务
xadmin引入django-debug-toolbar调试工具的更多相关文章
- Django之Django debug toolbar调试工具
一.安装Django debug toolbar调试工具 pip3 install django-debug-toolbar 如果出错命令为 pip install django_debug_tool ...
- 【Django】Django Debug Toolbar调试工具配置
正在发愁怎么调试Django,就遇到了Django Debug Toolbar这个利器. 先说遇到的问题: 网上也有教程,不过五花八门的,挨个尝试了一遍,也没有成功运行.最后终于找到问题所在: 从开发 ...
- 部署前准备--使用Mysql之Django Debug Toolbar安装以及配置
python -c "import django ;print(django.__path__);" 查看python的全局配置 vi /usr/local/lib/python3 ...
- django debug toolbar jquery加载配置
默认加载谷歌cdn的jquery: 显然国内是会悲剧的. 破解方案: 在settings.py中增加以下配置: DEBUG_TOOLBAR_CONFIG = {"JQUERY_URL&quo ...
- Django xadmin引入DjangoUeditor
Django xadmin引入DjangoUeditor 版本:python3.6.1,Django1.11.1 DjangoUeditor下载地址:https://github.com/twz915 ...
- django入门8之xadmin引入富文本和excel插件
django入门8之xadmin引入富文本和excel插件 Xadmin引入富文本 插件的文档 https://xadmin.readthedocs.io/en/docs-chinese/make_p ...
- xadmin引入drf-yasg生成Swagger API文档
一.安装drf-yasg: 由于django-rest-swagger已经废弃了 所以引入了drf-yasg pip install drf-yasg 安装install drf-yasg库 http ...
- xadmin引入django-ckeditor富文本编辑器
一.安装: pip install django-ckeditor 安装django-ckeditor库 https://github.com/django-ckeditor/django-ckedi ...
- django debug
django_debug_toolbar(略). debug toolbar还不够用,看下面. 1. 在对应的位置设置断点 import pdb pdb.set_trace() 2. runserve ...
随机推荐
- Lab_1:练习5——实现函数调用堆栈跟踪函数
题目:实现函数调用堆栈跟踪函数 我们需要在lab1中完成kdebug.c中函数print_stackframe的实现,可以通过函数print_stackframe来跟踪函数调用堆栈中记录的返回地址.如 ...
- golang socket与Linux socket比较分析
在posix标准推出后,socket在各大主流OS平台上都得到了很好的支持.而Golang是自带runtime的跨平台编程语言,Go中提供给开发者的socket API是建立在操作系统原生socket ...
- CSP-S2019 自闭记
$Day0:$ 最后一场zr十连测从200挂到60,嘴上说着攒rp心里觉得药丸. 得知自己在本校考试感觉8错. $Day1:$ 早上7点50到了校门口,没让进QAQ早知道我再下一把棋了. 于是跟熊聊天 ...
- count和distinct
一.count和distinct count是统计数据条数,distinct是去掉重复列: count统计的时候会忽略null值,distinct会将重复的null值列作为一个. 综上select c ...
- 集成开发环境(IDE)
学习目标: 1.了解Java的IDE开发工具 2.会使用Eclipse.IDEA开发工具新建项目,编写代码,并运行程序. 学习过程: 使用文本开发效率无疑是很低的,每次编写完代码后,还需要手动的编译执 ...
- Vue传递方法给页面调用
很多人在使用vue的时候苦于在vue中写方法,但是在外部甚至在另一个js该如何调用呢? 这个方法就是显示了vue的可以传递方法到页面使得页面任何地方都可以调用 前提得引用文件 这个方法一般多用于加载周 ...
- [MySql] - Windows MySql 8.x 手动zip包安装与外网访问登录权限设定
MySql 8.x官方下载地址 https://dev.mysql.com/downloads/mysql/8.0.html https://cdn.mysql.com//Downloads/MySQ ...
- Unity AsyncGPUReadback 接口测试
Unity2018新加入了该接口,可以做到异步RenderTexture->像素数据和异步的ComputeBuffer.GetData 那么写了几个例子来测试下. 1.RenderTexture ...
- PHP面试题2019年腾讯工程师面试题和答案
一.单选题(共29题,每题5分) 1.PHP执行的时候有如下执行过程:Scanning(Lexing) - Compilation - Execution - Parsing,其含义分别为: A.将P ...
- 2年java,蚂蚁一面,卒
其实我一个都没答上来.并不是因为我笨,是因为我不会.在大扰的帮助下,现在我会了,求求你再给我一个机会. TreeSet/HashSet 区别 顾名思义,首先是结构上的不同 1.TreeSet背后的结构 ...