def index(request): # 分类 menu = models.Menu.objects.all().filter(status=1) # banner banner = models.Banner.objects.all().filter(status=1) # 文章 article = models.Article.objects.all().annotate( comment_num=Count('comment')).filter(status=1).order_by("-add_time") # 分页并获取分页数 objects, page_range = Common.pagination(request, article) # 分类目录 menuArticleNum = models.Article.objects.values( 'menu', 'menu__menuname').annotate(num=Count('menu')).filter(status=1) # 文章热搜 hotArticle = models.Article.objects.all().filter( status=1).order_by("-hot")[0:10] # 热搜tag tagArticle = models.Article.objects.values('tag').annotate( num=Count('tag')).filter(status=1) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) print(BASE_DIR) return render( request, 'home/index/index.html', { 'menu': menu, 'banner': banner, 'article': objects, 'page_range': page_range, 'hotArticle': hotArticle, 'tagArticle': tagArticle, 'menuArticleNum': menuArticleNum, })
def menu(request,id): # 获取当前的菜单 #cur_menu = request.GET.get('m') cur_menu = id # 声明条件字典 kwargs = {} kwargs['menu'] = int(cur_menu) kwargs['status'] = 1 # 分类 menu = models.Menu.objects.all().filter(status=1) # banner banner = models.Banner.objects.all().filter(status=1) # 文章 article = models.Article.objects.all().annotate(comment_num=Count('comment') ).filter(**kwargs).order_by("add_time") # 分页并获取分页数 objects, page_range = Common.pagination(request, article) # 分类目录 menuArticleNum = models.Article.objects.values('menu','menu__menuname').annotate(num=Count('menu')).filter( status=1) # 文章热搜 hotArticle = models.Article.objects.all().filter( status=1).order_by("-hot")[0:10] # 热搜tag tagArticle = models.Article.objects.values('tag').annotate(num=Count('tag')).filter( status=1) return render(request, 'home/index/index.html', { 'menu': menu, 'cur_menu': cur_menu, 'banner': banner, 'article': objects, 'page_range': page_range, 'hotArticle': hotArticle, 'tagArticle': tagArticle, 'menuArticleNum': menuArticleNum, })
def get_remote_last_modified(self): """Return the last modified date of the remote HTTP file.""" dds_addr = self._get_opendap_addr() + '.dds' return Common.get_http_last_modified(dds_addr)
def get_local_last_modified(self): """Return the last modified date of the file on the opendap server.""" return Common.get_http_last_modified(self.file_url)
def get_tilemill_server_address(self): """ Return Tilemill server address ready for use. """ return Common.prepare_config_address(self.tilemill_server_address)
def get_thredds_server_address(self): """ Return thredds server address ready for use.""" return Common.prepare_config_address(self.thredds_server_address)
def get_zoo_server_address(self): """ Return zoo server address ready for use.""" return Common.prepare_config_address(self.zoo_server_address)