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

django 用 DeleteView 删除一个主题下面的某一个回复后。怎么让 success_url 返回当前主题页面呢? 如下。。

  •  
  •   python30 · 2019-01-01 12:40:22 +08:00 · 2020 次点击
    这是一个创建于 1933 天前的主题,其中的信息可能已经有所发展或是发生改变。
    class Delete_Reply(DeleteView):
    model = Reply
    template_name = 'bbs/delete_reply.html'
    success_url = reverse_lazy('bbs:index')

    现在删了一个回复只能返回首页
    如果 reverse_lazy('bbs:bbs_detail', pk = id)
    不知道这个 pk id 怎么传进来?
    4 条回复    2019-01-02 13:34:58 +08:00
    111111111111
        1
    111111111111  
       2019-01-01 13:39:50 +08:00 via Android
    python30
        2
    python30  
    OP
       2019-01-01 13:45:06 +08:00
    @111111111111
    这个 self 参数放在哪?
    qqxx520
        3
    qqxx520  
       2019-01-02 08:09:27 +08:00 via iPhone
    不要在类上,要在对象方法里获取,参考 get_success_url()
    xpresslink
        4
    xpresslink  
       2019-01-02 13:34:58 +08:00
    reverse_lazy('bbs:bbs_detail', kwargs={'pk': id} )

    这种情况建议直接在当前页用 ajax 直接 post 回复的 id 到后端删除。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5489 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 01:27 · PVG 09:27 · LAX 18:27 · JFK 21:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.