Skip to main content

comk_djanog_plugin

comk个人开发的django插件,用于很方便的记录日志、下载日志,以及其他拥有小功能的中间件

现有功能

1. 通用日志记录

  1. 先在settings中进行配置:

    MIDDLEWARE = [
        'django.middleware.security.SecurityMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'comk_django_plugin.middleware.ErrorLogMiddleware',  # 加上这一行,注意,添加的位置是非常重要的,建议添加在 auth 下面
        'comk_django_plugin.middleware.RequestLogMiddleware', # 加上这一行,注意,添加的位置是非常重要的,建议添加在 auth 下面
        'django.contrib.messages.middleware.MessageMiddleware',
        'django.middleware.clickjacking.XFrameOptionsMiddleware',
    ]
    
    import comk_django_plugin
    LOGGING = comk_django_plugin.auto_update_logsetting()  # 可传入各个项目自定义的LOGGING配置,会自动合并,同时生效。
  2. 通过django中间件实现对每个请求进行记录,记录类型有:
    • 记录请求数据和返回数据,并记录在 log/comk_request.log 下。

    • 记录错误日志,并记录在 log/comk_error_traceback.log 下。

    • 记录请求超时日志,并记录在 log/comk_long_response_time.log 下。

2. 日志下载

  1. 先在settings中进行配置:

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'comk_django_plugin.apps.ComkDjangoPluginConfig', # 加上这一行
    ]
  2. 然后在在urls.py下加上url配置:

    from django.conf.urls import url, include
    from django.contrib import admin
    
    urlpatterns = [
        url(r'^admin/', admin.site.urls),
        url(r'^', include('comk_django_plugin.urls')),
    ]
  3. 这样就可以直接在浏览器上输入地址,打开下载log文件的页面,如下:

    http://0.0.0.0:8000/getlog/log_download_html/
    
    该页面是一个简单的HTML,提供打包下载所有日志文件,以及下载单个日志文件的功能。

3. PublicServer文件

  1. 一个简单的通用服务的文件,目的是简化开发代码的书写,日后还会不断添加,使用方法如下:

    class OrderQuery(View):
        """
        查询订单历史,并生成excel文件
    
        """
    
        def post(self, request):
            ps = PublicServer(request)
            if not ps.check_login_user():
                return ps.return_build_error_response(msg='没有登录用户,请登录')

4. PublicDao文件

  1. 一个简单的通用数据库操作的文件,目的是简化开发代码的书写,日后还会不断添加,使用方法如下:

    class ModelDao(PublicDao):
        def __init__(model=Model):
            super().__init__(model)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

comk_django_plugin-1.4.4.tar.gz (13.9 kB view details)

Uploaded Source

File details

Details for the file comk_django_plugin-1.4.4.tar.gz.

File metadata

  • Download URL: comk_django_plugin-1.4.4.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for comk_django_plugin-1.4.4.tar.gz
Algorithm Hash digest
SHA256 e46e5351a5f5b63b581fe01c8bd2731acba81b82803c464de38d1f6c2fd2ff2a
MD5 8c4ff7727f6a461c5c969cabcc04ff81
BLAKE2b-256 7c386e13220343f469a681ba654aaac22fd98fa2ad9d17046db98f6e5004a193

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.4.4 This release

1 file

1.4.1

1 file

1.3.2

1 file

1.3.1

1 file

1.3.0

1 file

1.2.8

1 file

1.2.7

1 file

1.2.6

1 file

1.2.5

1 file

1.2.4

1 file

1.2.3

1 file

1.2.2

1 file

1.2.1

1 file

1.2.0

1 file

1.1.9

1 file

1.1.8

1 file

1.1.7

1 file

1.1.6

1 file

1.1.5

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page