form action="."

570 views
Skip to first unread message

rihad

unread,
Mar 8, 2009, 6:37:29 AM3/8/09
to Django developers
Chapter 7 of The Django Book says this:

The action="." means “Submit the form to the same URL as the current
page.”

I'm not sure this is standard or not, but it doesn't do what's
expected at least on Firefox 3.0.6 (Iceweasel of Debian 5.0 stable):
the form is simply submitted to an emtpy URL "/", which Django's web-
server logs on the console:

[08/Mar/2009 14:26:07] "GET /search HTTP/1.1" 200 205
[08/Mar/2009 14:26:10] "GET /?q= HTTP/1.1" 200 17

i.e. the first line shows me opening the form, and the next one logs
form submission, i.e. no HTTP-level redirects are ever done.

my urlpatterns looks like this:
...
(r'^search/*$', search),
...

that is, the trailing slash is optional. Very interestingly, the "."
action submits correctly to itself only if I open the form as "http://
example.com/search/", not as "http://example.com/search" in the first
place, as the Django Book recommends. So it would be more correct to
say that "action="." submits the form to the same URL up to and
including the trailing slash, ignoring everything after it".

Malcolm Tredinnick

unread,
Mar 8, 2009, 6:51:48 AM3/8/09
to django-d...@googlegroups.com
On Sun, 2009-03-08 at 03:37 -0700, rihad wrote:
> Chapter 7 of The Django Book says this:

When the updated version of Chapter 7 of the django boook is released
online, if the same description persists, it would be worth making a
comment over there. Although the book is written by two of the primary
authors of Django and being updated by one of them (Adrian), this list
isn't the place to report bugs, since we have nothing to do with the
content of that book.

Basically, though, any relative URL is going to relative to the portion
of the URL prior to (and including) the final slash. It behaves
identically to relative paths in filesystems in that respect. That's one
of the reasons why ending most URLs that don't request a particular
static file with a trailing slash isn't a bad idea. It makes relative
URLs a little easier to control: you don't have to know the name of the
current page to submit a form back to itself.

Regards,
Malcolm

rihad

unread,
Mar 8, 2009, 2:08:15 PM3/8/09
to Django developers
> When the updated version of Chapter 7 of the django boook is released
> online, if the same description persists, it would be worth making a
> comment over there.
Well, I'd hate sounding mean, but the wording was already taken from
v2.0: http://www.djangobook.com/en/2.0/chapter07/

> Although the book is written by two of the primary
> authors of Django and being updated by one of them (Adrian), this list
> isn't the place to report bugs, since we have nothing to do with the
> content of that book.
Good idea, thanks. I can't use the comment system, though: nothing
happens according to the docs at http://www.djangobook.com/about/comments/
Reply all
Reply to author
Forward
0 new messages