标签:bsp def 加载 imp remote object rom print 上下文
在app中创建context_processes.py(可以是别的名字),然后加载到settings里,这样所有的网页都可以传入变量
from .models import User def app01_context(request): context = {} user_id = request.session.get(‘user_id‘) ip = request.META[‘REMOTE_ADDR‘] print(‘上下文内容:‘,user_id, ip) try: login_user = User.objects.get(pk=user_id) context[‘login_user‘] = login_user context[‘ip‘] = ip except: pass return context
标签:bsp def 加载 imp remote object rom print 上下文
原文地址:https://www.cnblogs.com/fengzi7314/p/10351722.html