Django - Emulate a http-post request
I have this view function search(request)
. The url suffix is /search
. It takes a few POST parameters and shows search results accordingly.
I want to make a second function show_popular(request)
. It takes no post开发者_开发技巧 or get parameters. But it should emulate a call to the search function with some hard coded post parameters.
I want to achieve this without changing anything in any existing function and without changing setup. Is that possible?
EDIT: I know this can be achieved by refactoring the search into a separate function and have several view functions call this. But in this particular case, I am not interested in that. In my case the show_popular function is only temporary, and for irrelevant reasons I do not wish to re-factor.
Yes, but you don't want to do that. Refactor search()
into a function that handles the request and a function that performs the search, and call the latter from show_popular()
.
精彩评论