zoukankan      html  css  js  c++  java
  • Django各个文件中常用模块的导入

    Django各个文件中常用模块的导入

    '''
    用于分类各个py文件中导入模块的分类
    '''
    

    models.py

    from django.db import models
    

    urls.py

    from django.conf.urls import url, include
    from django.contrib import admin
    ...
    

    myforms.py

    from django import forms
    

    views.py

    # 反向解析
    from django.urls import reverse
    
    # return response
    from django.shortcuts import render, redirect, HttpResponse
    
    # json 数据返回(ajax)
    from django.http import JsonResponse
    
    # 配置文件
    from django.conf import settings
    
    # Q,F查询
    from django.db.models import Q
    

    routing.py

    # websocket的路由系统模块
    from channels.routing import ProtocolTypeRouter, URLRouter
    from django.conf.urls import url
    from channels.sessions import SessionMiddlewareStack
    from apps.web import consumers
    

    consumers.py

    # 应用websocket时需要导入的模块
    
    # websocket的链接与断开
    from channels.generic.websocket import WebsocketConsumer
    
    # channel_layer的组操作
    from asgiref.sync import async_to_sync
    
    	# group_add,添加task_id 到群里
    	async_to_sync(self.channel_layer.group_add)(task_id, self.channel_name)
    	
    	# group_send 发送message
    	async_to_sync(self.channel_layer.group_send)(task_id, 			{'type': 'xxx.ooo',	'message': 'message'})
    
    	# group_discard 断开链接
    	async_to_sync(self.channel_layer.group_discard)(task_id, self.channel_name)
    
    
    # 异常抛出
    from channels.exceptions import StopConsumer
    
    # 事务
    from django.db import transaction
    

    template

    # 静态文件引入
    {% load staticfiles %}
    
    # 自定义标签/过滤器的应用:templatetags文件夹下文件
    
    from django.template import Library
    
    	# HTML页面导入
    	{% load deploy %}
    	{% un_deploy_num obj %}
    
    # 模板继承
    {% extends "base/layout.html" %}
    
    # 组件应用
    {% include 'include/delete.html' %}
    希望你眼眸有星辰,心中有山海,从此以梦为马,不负韶华
  • 相关阅读:
    函数指针
    单链表的建立
    系统程序员成长计划组合的威力(三)
    通过XML构建TreeView
    关于Dll中导出string的问题
    关于类的拷贝构造函数、赋值构造函数探究
    系统程序员成长计划组合的威力(四)
    指纹识别软件安装包下载
    javaSE视频教程正式启动
    数组复习
  • 原文地址:https://www.cnblogs.com/daviddd/p/12053004.html
Copyright © 2011-2022 走看看