from django.views import generic from blog.models import * from ipware.ip import get_ip class IndexView(generic.ListView): template_name = 'lw-index-noslider.html' # 加载该html文件 context_object_name = "articles" # 是数据库搜索出来的结果存放的变量名字,用于模板循环显示 paginate_by = 4 # 设置分页中每一页的记录数目 model = Article # 定义从哪份model中查询 def get_queryset(self): return Article.objects.filter(show_status=True).order_by('-time_created') def get_context_data(self, **kwargs): context = super(IndexView, self).get_context_data(**kwargs) context['cloudtags'] = Tag.objects.filter().order_by("-id")[:8] context['nodes'] = Node.objects.filter().order_by("-id")[:8] context['quotations'] = get_quotations(2) return context def dispatch(self, request, *args, **kwargs): # Try to dispatch to the right method; if a method doesn't exist, # defer to the error handler. Also defer to the error handler if the # request method isn't on the approved list. # 这里的 request 就是普通 view 里面 request print(get_ip(request)) if request.method.lower() in self.http_method_names: handler = getattr(self, request.method.lower(), self.http_method_not_allowed) else: handler = self.http_method_not_allowed return handler(request, *args, **kwargs)
Zhuoyuebiji ( 广东·深圳 )
🚩成长的时候,能帮有需要的你
我是 卓越笔记,软件测试工作者,热爱互联网,喜欢琢磨,遇到问题就一定要找到答案。我的博客主要记录学习中遇到的知识点和遇到的问题及问题的解决方法。欢迎同样热爱互联网的小伙伴们交换友链,一起探索互联网的世界 😊
为向您提供更好的服务,我们使用 Cookies。更多相关信息请查阅我们的 隐私政策 和 免责声明