Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k views
in Technique[技术] by (71.8m points)

Django - How to carry the filters to the next view?

I imagine something like this is possible in Django, but I don't know how to implement it:

I have a TableView, which has filters to filter the displayed queryset. I, then, have a DetailView which you can access from the TableView, to see the details of each element in the queryset.

The DetailView has a form, which uses the POST method. I can successfully send the form, and redirect to the TableView after the POST call. My question is, how can I make it so that after the user calls the POST method in the DetailView, and it redirects again to the TableView, the TableView keeps whichever values were on its filters?

I imagine I would have to either get access to the full request on the TableView (because it includes the ?param1=?param2= etc.), or be able to send the values in the filters when I call the DetailView.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I believe the POST data is stored in request.data. This should be stored in a dictionary so you could iterate through request.data with a for loop to extract the posted data into variables. Then you can do whatever with those variables.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...