当前位置: 动力学知识库 > 问答 > 编程问答 >

python - How to redirect from one view to another?

问题描述:

I have an x view that redirects me to some_name.html page.

This view needs to create a class that it is importing from other python file.

This view calls a specific function (algorithm) that has some logic in it.

lets say this func return a dictionary.

I want that view 'x' will redirect me to negotioate.html page with this dynamic return dictionary.

When the user gets the output he should choose from 3 options and basically trigger the algorithm again.

Meaning, I want in each of those trigger to display the user the algo output but without reidrecting me to other page, but refreshing the current one.

网友答案:

Try :

url(r'^(?P<object_id>\d+)/$', edit, name="edit"),

OR

Return :

return redirect('quizzes.views.quizView', quizNumber=quizNumber)
网友答案:

Hi you can redirect from one view to another with data.

Try this code which I am using for my project also.

def notification_view(request,pk):
    notification_to_edit=notifications.objects.get(pk=pk)
    notification_to_edit.viewed = True
    notification_to_edit.save()
    return HttpResponseRedirect(reverse('taskdetail',kwargs={'pk':notification_to_edit.task_id.id}))

You need to use AJAX method to avoid page refresh. This view will reload the page, but code should work fine.

分享给朋友:
您可能感兴趣的文章:
随机阅读: