V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
bb2018
V2EX  ›  Python

v2ex 的 /?tab=jobs 或 /?tab=qna 这样查询是怎么用 django 实现的?我的实现方法大家看看思路对不?

  •  
  •   bb2018 · 2017-08-03 17:24:02 +08:00 · 1771 次点击
    这是一个创建于 2458 天前的主题,其中的信息可能已经有所发展或是发生改变。
    v2ex 的 /?tab=jobs 或 /?tab=qna  通过这个词,调用列表,这样查询是怎么用 django 模糊查询实现的?我的实现方法大家看看思路对不?

    本人新手,
    我觉得像是 django 模糊查询
    我用这写法
      class index(ListView):
    model = Topic
    template_name = 'bbs/index.html'
    context_object_name = 'bbs_list'

    def get_queryset(self):
    keyword = self.kwargs.get("keyword", None)
          print keyword
    if keyword == 'new':
    bbs_list = Topic.objects.all().order_by('-pub_date')#首页列表按时间最新排序
    elif keyword == 'good':
    bbs_list = Topic.objects.filter(good=True) # 首页列表只调用精华贴子
    else:
    bbs_list = Topic.objects.filter('-reply') # keyword 为空或者其它任意词,首页列表都按最新回复调用
    return bbs_list

    这思路对不?

    正确的写法应该是什么?
    1 条回复    2017-08-03 18:47:18 +08:00
    xiqingongzi
        1
    xiqingongzi  
       2017-08-03 18:47:18 +08:00
    ?tab=jobs 是 get 方法的参数,参数名为 tab 参数值为 jobs
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2859 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 11:59 · PVG 19:59 · LAX 04:59 · JFK 07:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.