简体   繁体   中英

HTML Forms without actions

In Django / Pinax, I've come across the login form which starts like this :

<form class="login" method="POST" action="">

It works perfectly well. So I assume that either some java-script or something in the Django framework is putting the value into the action attribute.
So, my questions:

  • How does Django insert the action?
  • Why do they do it like this?
  • How can I find out what the action of this form is?

Update : I see this is not a Django thing at all, but what most browsers do.

在大多数浏览器中执行空字符串操作会将表单指向浏览器当前加载的URL,这是首先为表单提供服务的脚本。

有关使用空操作的表单的有趣见解,请阅读此主题 ,该主题为您提供有关此问题的更新HTML5视角。

It's also possible that javascript loaded with this page could be setting an action once the page is loaded based on what application is using the page.

Another likely possibility is that the javascript is handling the onsubmit event. One might do that to prevent the page from reloading or redirecting to a specific page

I guess it's bit late to answer this post. Anyways, I'll what I learnt about this.

If the "action" is not specified in forms, then the Django looks up the HttpResponseRedirect in the corresponding view.

For example, in the example below:

if form.is_valid(): # All validation rules pass
        # Process the data in form.cleaned_data
        # ...
        return HttpResponseRedirect('/thanks/')

Once, the form is validated (and processed), the page is redirected to 'thanks'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM