如何从Django视图中定位页面?

时间:2015-12-29 12:58:59

标签: html django

我无法在django视图的特定位置打开网页。提交表单后,我希望它显示在哪里,但我不知道它在模板本身的位置,因为该信息是表单值。

1 个答案:

答案 0 :(得分:0)

听起来您需要将成功网址定义为提交表单的同一页面以及锚点。

例如:

from os.path import join

class MyFormView(FormView):
    template_name='some_form_template.html'

    def get_success_url(self):
        """
        Returns the supplied success URL.
        """
        return join(reverse('viewname'), '#anchor')

some_form_template.html模板中:

<a id="anchor">Where you'd like the user to be dropped on the page.</a>

如果表单验证成功,页面将刷新,用户将被删除到该模板上指定的锚点。

相关问题