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' %}
posted @ 2019-12-17 10:23  阿浪阿浪  阅读(496)  评论(0编辑  收藏  举报