How to pass information using an HTTP redirect (in Django)

后端 未结 11 880
北恋
北恋 2021-02-01 19:22

I have a view that accepts a form submission and updates a model.

After updating the model, I want to redirect to another page, and I want a message such as \"Field X su

11条回答
  •  悲&欢浪女
    2021-02-01 20:10

    You could also have the redirect url be the path to an already parameterized view.

    urls.py:

    (r'^some/path/(?P\w+)/$', direct_to_template,
        {'template': 'field_updated_message.html',
        },
        'url-name'
    ),
    

    views.py:

    HttpResponseRedirect( reverse('url-name', args=(myfieldname,)) )
    

    Note that args= needs to take a tuple.

提交回复
热议问题