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

Django的URL传参问题

  •  
  •   melaozhu ·
    laozhu · 2013-11-05 16:21:54 +08:00 · 4060 次点击
    这是一个创建于 3823 天前的主题,其中的信息可能已经有所发展或是发生改变。
    ## ListView
    http://domain.com/user?page=2

    这是一个列表页面,有分页。在这个页面里面有几个链接分别跳转到

    ## CreateView {% url 'new-user' %}
    ## UpdateView {% url 'update-user' %}
    ## DeleteView {% url 'delete-user' %}

    点击进入相应的页面,完成新增,修改,删除后再跳转回ListView页面

    class UserCreateView(CreateView):
    def get_success_url(self):
    return reverse('staff-list')

    怎样把page参数传给CreateView?,如何回到page=2这个分页,而不是ListView的首页?
    5 条回复    1970-01-01 08:00:00 +08:00
    JohnSmith
        1
    JohnSmith  
       2013-11-05 17:00:32 +08:00
    404 not found
    mengzhuo
        2
    mengzhuo  
       2013-11-05 19:33:52 +08:00
    本身设计就有问题……你怎么知道一定是page=2的分页?

    p.s. 硬要整的话可以参考标准库urlparse
    melaozhu
        3
    melaozhu  
    OP
       2013-11-06 08:50:09 +08:00
    @mengzhuo 我只是举了个栗子啊,我想问的是URL中?后的参数怎么传
    MichaelYin
        4
    MichaelYin  
       2013-11-06 11:59:20 +08:00   ❤️ 1
    如果你的列表页只有分页的page参数而没有其他的参数其实可以考虑下url重定向,就是将page参数直接写到URL里面去,用正则取出page参数

    比如http://domain.com/user_2
    这样就代表userlist第二页
    MichaelYin
        5
    MichaelYin  
       2013-11-06 12:05:26 +08:00
    另外一种方法就是对URL进行编码处理后,然后放到一个querystring里面去,关于URL编码请Google
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1318 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 17:50 · PVG 01:50 · LAX 10:50 · JFK 13:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.