Well, in investigating this further, I think I found the 'issue'.
There are a few threads with similar issues, where the pattern in
urls.py doesn't capture the trailing slash, and I guess by default,
django figures it will 'adjust' the URL and redirect to the 'correct'
URL, hence the initial 301, which I think for most cases is great.
My original urls.py was:
(r'^announce/$', 'track.views.announce'),
and that was causing a 301 if I went to
127.0.0.1:8000/announce.
If I added
(r'^announce$', 'track.views.announce')
so my urls.py looks like this:
(r'^announce/$', 'track.views.announce'),
(r'^announce$', 'track.views.announce')
when run with the urls.py above, it ran as expected without the 301
redirect.
So here's the rub, this is awesome for probably most applications, but
when django does the redirect under the dev server, with a complicated
escaped parameter it seems like it mangles the parameters on the
redirect.
To test this, I pointed a bittorrent client at my test announce client
(it doesn't do anything but return 'hello world', so the client will
just assume it's a bad tracker, but for purposes of testing....
With the urls.py w/o adjusting for 301 'features':
urls.py
(r'^announce/$', 'track.views.announce')
runserver output:
[04/Jun/2008 09:47:29] "GET /announce?info_hash=%10%C2%E1%96%E0%8D
%90%05%B7%DF%C
6%BC%8E%C2%15%E4%3D%60%CC
%84&peer_id=T03I-----7oWWIp1FS9B&port=57328&uploaded=0&
downloaded=0&left=0&no_peer_id=1&compact=1&event=started&key=-UIpWN
HTTP/1.1" 30
1 0
[04/Jun/2008 09:47:29] "GET /announce/?
uploaded=0&compact=1&no_peer_id=1&info_ha
sh=%10%EF%BF%BD%EF%BF%BD%EF%BF%BD%05%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF
%BD%EF%BF%B
D%EF%BF%BD%CC%84&event=started&downloaded=0&key=-
UIpWN&peer_id=T03I-----7oWWIp1F
S9B&port=57328&left=0 HTTP/1.1" 200 5
with the urls.py adjusted to avoid the 301.
(r'^announce$', 'track.views.announce'),
(r'^announce/$', 'track.views.announce'),
runserver output:
[04/Jun/2008 09:49:36] "GET /announce?info_hash=%10%C2%E1%96%E0%8D
%90%05%B7%DF%C
6%BC%8E%C2%15%E4%3D%60%CC
%84&peer_id=T03I-----6HsE05d95lH&port=17242&uploaded=0&
downloaded=0&left=0&no_peer_id=1&compact=1&event=started&key=Jq-8Ta
HTTP/1.1" 20
0 5
Note the difference?
When django does the redirect for the 301 the parameters change,
specifically info_hash:
before 301
info_hash=%10%C2%E1%96%E0%8D%90%05%B7%DF%C6%BC%8E%C2%15%E4%3D%60%CC%84
After 301
info_hash=%10%EF%BF%BD%EF%BF%BD%EF%BF%BD%05%EF%BF%BD%EF%BF%BD%EF%BF%BD
%EF%BF%BD%EF%BF%BD%EF%BF%BD%CC%84
Am I right in my observations?
Is there anything I can do to avoid this in django? HELP, THIS IS
REALLY HOLDING ME UP. In the mean time, I'll capture the slashes
better.
Thanks,
John
On Jun 4, 9:30 am, John M <
retireonc...@gmail.com> wrote:
> I am running into some weirdness in an app im writing and so I thought
> I'd try to see how the basics of URL strings are handled.
>
> So I wrote a one line hello world app, and wanted to see how the dev
> server output it's results. I am still getting my feet wet with the
> whole web / http / HTML thing, these may be silly questions.
>
> Here's my view.py
> from django.http import HttpResponse
>
> def announce(request):
> return HttpResponse("Hello")
>
> the urls.py maps announce/$ to this view, and that is working.
>
> What's odd, is when I goto my browser and dohttp://localhost:8000/announce,