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
ciba1990
V2EX  ›  Python

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

  •  
  •   ciba1990 · 2015-07-22 15:40:10 +08:00 · 2024 次点击
    这是一个创建于 3216 天前的主题,其中的信息可能已经有所发展或是发生改变。

    以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 条回复    2015-07-29 22:48:18 +08:00
    ciba1990
        1
    ciba1990  
    OP
       2015-07-22 15:54:41 +08:00
    模板用的django
    fyl00
        2
    fyl00  
       2015-07-22 16:01:17 +08:00   ❤️ 1
    views.py 里面通过 request.GET 来获得参数。比如 request.GET['q']
    https://docs.djangoproject.com/en/1.8/intro/tutorial04/
    wy315700
        3
    wy315700  
       2015-07-22 16:03:40 +08:00   ❤️ 1
    最基本的GET啊
    ciba1990
        4
    ciba1990  
    OP
       2015-07-22 16:05:37 +08:00
    @fyl00 我的意思是获取网址的参数,request.GET['pn']没有用,因为我改变的只是网址
    ciba1990
        5
    ciba1990  
    OP
       2015-07-22 16:05:54 +08:00
    @wy315700 能给个实例吗
    ciba1990
        6
    ciba1990  
    OP
       2015-07-22 16:08:06 +08:00
    @ciba1990
    @fyl00
    不好意思 代码写错了,我说怎么卡住了呢,解决了。
    wy315700
        7
    wy315700  
       2015-07-22 16:08:32 +08:00
    @ciba1990
    2楼的方法啊,不知道你的获取参数是本地JS获取还是Server获取
    sobigfish
        8
    sobigfish  
       2015-07-22 16:37:26 +08:00
    肯定是前端完成的吧
    HTML5 history API + URI 识别
    https://github.com/browserstate/history.js
    https://github.com/medialize/URI.js
    mingyun
        9
    mingyun  
       2015-07-29 22:48:18 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2179 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 00:45 · PVG 08:45 · LAX 17:45 · JFK 20:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.