django - 当视图需要参数时,表单操作参数中的内容是什么? [英] django - what goes into the form action parameter when view requires a parameter?

查看:17
本文介绍了django - 当视图需要参数时,表单操作参数中的内容是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我所拥有的:

myview.py 带有一个带有参数 user 的视图:

myview.py with a view that takes a parameter user:

def myview(request, user):
   form = MyForm(request.POST)
   ....
   return render_to_response('template.html',locals(), context_instance=RequestContext(request))

user 通过 url 传递.

The user gets passed through an url.

urls.py:

...

urlpatterns += patterns('myview.views',
    (r'^(?P<user>w+)/', 'myview'),
)

...

我还有一个带有表单的 template.html:

I also have a template.html with a form:

<form name="form" method="post" action=".">
...
</form>

如果myview 函数需要一个参数,那么表单操作参数中的内容是什么?

What goes in the the form action parameter if myview function requires a parameter?

现在我有 action="." .我问的原因是因为当我在 (templates.html) 中填写表单并单击提交按钮时,我绝对没有看到从该表单传递的字段值.当我单击提交按钮时,这几乎就像我传递了一个空表单.有任何想法吗?谢谢!

Right now I have action="." . The reason I'm asking is because when I fill up the form In (templates.html) and click the submit button I see absolutely no field values passed from that form. It's almost like I'm passing an empty form when I click the submit button. Any ideas? Thank you!

推荐答案

您正在发布到同样为表单提供服务的视图.所以首先,视图被调用并服务于表单.当您发布表单时,会调用相同的视图,但这次您处理表单.这就是为什么动作是空的.

You are posting to the same view that also serves the form. So at first, the view is called and serves the form. When you post the form, the same view gets called but this time you process the form. That's why the action is empty.

这篇关于django - 当视图需要参数时,表单操作参数中的内容是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆