32

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.

asked Mar 13, 2009 at 2:47

4 Answers 4

43

Having an action of an empty string in most browsers points the form at the URL the browser currently has loaded, which is the script that served the form in the first place.

answered Mar 13, 2009 at 2:57
Sign up to request clarification or add additional context in comments.

3 Comments

ah. I didn't know that. So is this just laziness or is it good practice to rely on this
i'd say good practice, since you reduce the number of urls in your code. but I prefer not putting the action at all. does any browser out there need the empty action?
Forms without action attrbiute work fine in all mainstream browsers. However the action attribute is mandatory if you want your HTML to validate.
6

For an interesting insight on forms with empty actions read this thread, which gives you an updated HTML5-perspective on this matter.

answered Aug 16, 2012 at 20:22

Comments

4

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

answered Mar 13, 2009 at 17:58

Comments

0

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'

answered Jul 24, 2014 at 10:07

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.