推荐学习书目
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
ciba1990
V2EX  ›  Python

怎么改变网址能够传递参数到变量

  •  
  •   ciba1990 · Jul 22, 2015 · 2786 views
    This topic created in 3980 days ago, the information mentioned may be changed or developed.

    以360搜索为例:设想通过改变网址最后的pn对应值就能传递到python变量。
    http://www.haosou.com/s?q=tg&pn=8
    毫无头绪,不知道360搜索是怎么做到的,请大神指点。
    <form action="/s">
    <fieldset id="input-container">
    <input type="hidden" name="pn" value="{{num}}">
    <input type="text" name="q" class="placeholder" id="input" suggestWidth="528px" autocomplete="off">
    <input type="submit" id="search-button" value="search">
    </form>

    9 replies    2015-07-29 22:48:18 +08:00
    ciba1990
        1
    ciba1990  
    OP
       Jul 22, 2015
    模板用的django
    fyl00
        2
    fyl00  
       Jul 22, 2015   ❤️ 1
    views.py 里面通过 request.GET 来获得参数。比如 request.GET['q']
    https://docs.djangoproject.com/en/1.8/intro/tutorial04/
    wy315700
        3
    wy315700  
       Jul 22, 2015   ❤️ 1
    最基本的GET啊
    ciba1990
        4
    ciba1990  
    OP
       Jul 22, 2015
    @fyl00 我的意思是获取网址的参数,request.GET['pn']没有用,因为我改变的只是网址
    ciba1990
        5
    ciba1990  
    OP
       Jul 22, 2015
    @wy315700 能给个实例吗
    ciba1990
        6
    ciba1990  
    OP
       Jul 22, 2015
    @ciba1990
    @fyl00
    不好意思 代码写错了,我说怎么卡住了呢,解决了。
    wy315700
        7
    wy315700  
       Jul 22, 2015
    @ciba1990
    2楼的方法啊,不知道你的获取参数是本地JS获取还是Server获取
    run2
        8
    run2  
       Jul 22, 2015
    肯定是前端完成的吧
    HTML5 history API + URI 识别
    https://github.com/browserstate/history.js
    https://github.com/medialize/URI.js
    mingyun
        9
    mingyun  
       Jul 29, 2015
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2895 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 09:07 · PVG 17:07 · LAX 02:07 · JFK 05:07
    ♥ Do have faith in what you're doing.