I'm attempting to upgrade my Pylons app to 0.9.7, but I can't seem to get past the "302 you will now be redirected" problem.
What I did was I created a totally new Pylons app, and then I started moving my controllers and models and things across. I'm not sure if this is the best way, but I figured it was most probably the easiest. I also read through the "What's new in 0.9.7" document and the "Upgrading" document on the wiki, and followed directions as much as I could.
I've left map.minimize on False, and I added the extra lines in my routes.py file as per the documentation. I also made sure that my middleware.py file had the necessary lines. I also modified base.py and the BaseController class, because my authentication system checks for a valid user in the __before__ function.
Now the problem comes in that when I hit the main page, my default controller sees that there's no user logged in and tries to redirect me to the login page. Except it just sits there saying "302 Found The resource was found at http://localhost:5000/member/login/; you should be redirected automatically." and never redirects me.
The only thing I can think of is that you aren't including redirect_to(),
which isn't included by default anymore. That's located under "Import
changes" on the What's new (I know you said you followed it but it may have
slipped by). http://wiki.pylonshq.com/pages/viewpage.action?pageId=11174779
Hope that helps,
Brian
On Wed, Nov 19, 2008 at 10:28 AM, Raoul Snyman <raoul.sny...@gmail.com>wrote:
> I'm attempting to upgrade my Pylons app to 0.9.7, but I can't seem to
> get past the "302 you will now be redirected" problem.
> What I did was I created a totally new Pylons app, and then I started
> moving my controllers and models and things across. I'm not sure if
> this is the best way, but I figured it was most probably the easiest.
> I also read through the "What's new in 0.9.7" document and the
> "Upgrading" document on the wiki, and followed directions as much as I
> could.
> I've left map.minimize on False, and I added the extra lines in my
> routes.py file as per the documentation. I also made sure that my
> middleware.py file had the necessary lines. I also modified base.py
> and the BaseController class, because my authentication system checks
> for a valid user in the __before__ function.
> Now the problem comes in that when I hit the main page, my default
> controller sees that there's no user logged in and tries to redirect
> me to the login page. Except it just sits there saying "302 Found The
> resource was found at http://localhost:5000/member/login/; you should
> be redirected automatically." and never redirects me.
On Wed, Nov 19, 2008 at 7:28 AM, Raoul Snyman <raoul.sny...@gmail.com> wrote:
> Hi all,
> I'm attempting to upgrade my Pylons app to 0.9.7, but I can't seem to > get past the "302 you will now be redirected" problem.
> What I did was I created a totally new Pylons app, and then I started > moving my controllers and models and things across. I'm not sure if > this is the best way, but I figured it was most probably the easiest. > I also read through the "What's new in 0.9.7" document and the > "Upgrading" document on the wiki, and followed directions as much as I > could.
> I've left map.minimize on False, and I added the extra lines in my > routes.py file as per the documentation. I also made sure that my > middleware.py file had the necessary lines. I also modified base.py > and the BaseController class, because my authentication system checks > for a valid user in the __before__ function.
> Now the problem comes in that when I hit the main page, my default > controller sees that there's no user logged in and tries to redirect > me to the login page. Except it just sits there saying "302 Found The > resource was found at http://localhost:5000/member/login/; you should > be redirected automatically." and never redirects me.
I have a similar authentication system in a Pylons 0.9.7 app so I can verify it works.
Looking at your modules, I didn't know Routes had an .append_slash option but that could be throwing it off. There's no reason to put slashes at the end of URLs except to make it look like a directory to the user, but even then it's not necessary (/messages and /messages/1234 work fine).
There's another redirect_to function in pylons.controllers.util which you should be using instead, as routes.redirect_to is being phased out. But they should both behave the same.
You should be putting h.url_for() around all URLs, as that will adjust the URL if it needs a prefix someday. Or you can use Pylons 0.9.7's fancy url() object (pylons.url), which will be its replacement in Pylons 1.0.
You can turn on route debugging to see if it gives any clues. Add this to development.ini:
And add 'routes' to the 'keys' option in [loggers].
If none of these help, I would check your app under Live HTTP Headers to see what it's actually doing. The 302 response should have a Location: header with the absolute URL to redirect to.
On Wed, Nov 19, 2008 at 7:05 PM, Mike Orr <sluggos...@gmail.com> wrote: > Looking at your modules, I didn't know Routes had an .append_slash > option but that could be throwing it off. There's no reason to put > slashes at the end of URLs except to make it look like a directory to > the user, but even then it's not necessary (/messages and > /messages/1234 work fine).
I prefer ending urls with / :-D
> You can turn on route debugging to see if it gives any clues. Add > this to development.ini:
Thanks to the above bit of extra debugging, I found out what my problem was... in my routing.py (which I erroneously called "routes.py" earlier) I had the following lines:
On Nov 19, 2:20 pm, "Raoul Snyman" <raoul.sny...@gmail.com> wrote:
> On Wed, Nov 19, 2008 at 7:05 PM, Mike Orr <sluggos...@gmail.com> wrote:
> > Looking at your modules, I didn't know Routes had an .append_slash
> > option but that could be throwing it off. There's no reason to put
> > slashes at the end of URLs except to make it look like a directory to
> > the user, but even then it's not necessary (/messages and
> > /messages/1234 work fine).
> I prefer ending urls with / :-D
This is somewhat off topic, but I used to prefer the above too. Then
I had a page referenced by that type of URL that needed query string
arguments. I ended up with a URL like this:
example.com/this/page/?foo=bar
Having the whole "/?" thing just killed this idea for me. Now all my
routes specifically do not end in a slash. Anyone else have thoughts
on this?
On Wed, Nov 19, 2008 at 2:43 PM, Randy Syring <rsyr...@gmail.com> wrote:
> On Nov 19, 2:20 pm, "Raoul Snyman" <raoul.sny...@gmail.com> wrote: >> On Wed, Nov 19, 2008 at 7:05 PM, Mike Orr <sluggos...@gmail.com> wrote: >> > Looking at your modules, I didn't know Routes had an .append_slash >> > option but that could be throwing it off. There's no reason to put >> > slashes at the end of URLs except to make it look like a directory to >> > the user, but even then it's not necessary (/messages and >> > /messages/1234 work fine).
>> I prefer ending urls with / :-D
> This is somewhat off topic, but I used to prefer the above too. Then > I had a page referenced by that type of URL that needed query string > arguments. I ended up with a URL like this:
> example.com/this/page/?foo=bar
> Having the whole "/?" thing just killed this idea for me. Now all my > routes specifically do not end in a slash. Anyone else have thoughts > on this?
I don't remember where I read it but URLs ending with / are supposed to be directories so the above behavior is wrong for webapps.
On Wed, Nov 19, 2008 at 9:07 PM, Jorge Vargas <jorge.var...@gmail.com> wrote:
> On Wed, Nov 19, 2008 at 2:43 PM, Randy Syring <rsyr...@gmail.com> wrote:
>> On Nov 19, 2:20 pm, "Raoul Snyman" <raoul.sny...@gmail.com> wrote: >>> On Wed, Nov 19, 2008 at 7:05 PM, Mike Orr <sluggos...@gmail.com> wrote: >>> > Looking at your modules, I didn't know Routes had an .append_slash >>> > option but that could be throwing it off. There's no reason to put >>> > slashes at the end of URLs except to make it look like a directory to >>> > the user, but even then it's not necessary (/messages and >>> > /messages/1234 work fine).
>>> I prefer ending urls with / :-D
>> This is somewhat off topic, but I used to prefer the above too. Then >> I had a page referenced by that type of URL that needed query string >> arguments. I ended up with a URL like this:
>> example.com/this/page/?foo=bar
>> Having the whole "/?" thing just killed this idea for me. Now all my >> routes specifically do not end in a slash. Anyone else have thoughts >> on this?
> I don't remember where I read it but URLs ending with / are supposed > to be directories so the above behavior is wrong for webapps.
Say you have a static server like this:
/dir/ index.html other.html
The user requests "/dir/index.html", which contains a link to "other.html". The base URL is "/dir/", so the browser does a join and comes up with "/dir/other.html".
Or the user requests "/dir/". The server assumes the default document, index.html. Again the base URL is "/dir/", and the relative link resolves to "/dir/other.html".
Or the user requests "/dir". This ends in a directory so the server issues a redirect to "/dir/", and then serves the default document. The base URL and resolved link are the same.
If the server didn't issue a redirect but served index.html directly, the base URL would be "/dir". The browser wouldn't know this is a directory so it assumes "dir" is the current document and drops it before joining:
"/dir" - "dir" + "/other.html" => "/other.html"
which is the wrong URL and doesn't exist.
In a non directory-based framework like Pylons, the choice of what to serve for "/foo", "/foo/", and "/foo/bar" are arbitrary. Pylons can't automatically redirect "/foo" because it doesn't know it's supposed to be a directory. It can't divine that "/foo/bar" exists and "/foo/NONEXISTENT" doesn't, because that's only known when those URLs are requested. So, you have a choice:
1) Serve "/foo" as a container and let "/foo/" not exist, which is what most Pylons apps do. 2) Redirect "/foo" to "/foo/". 3) Serve identical content for "/foo" and "/foo/". 4) Serve different content for "/foo" and "/foo/".
The trouble with #4 is thinking up a practical case for it. When do you need two slightly different indexes? Perhaps a title page and a table of contents. But nobody does it that way, and it's prone to human misperception or browser misperception given the precendent of static files.
The corollary is that relative URLs don't work with the default Pylons case. You may be able to get from "/foo/bar" to "/foo/baz" with a link to "baz", and if you're lucky you might be able to get to "/foo/index" with "./", or "/foo" with "..", but it depends on your routing. This is one reason why Pylons (and TurboGears and Rails) discourage relative URLs in favor of url_for(), which generates a fully-qualified, unambiguous URL.
Another aspect is that users don't like to type trailing slashes. They also don't know whether something is a container, so they'll type "http://example.com/articles" because somebody told them there's an articles URL.
Mike Orr wrote: > 1) Serve "/foo" as a container and let "/foo/" not exist, which is > what most Pylons apps do. > 2) Redirect "/foo" to "/foo/".
Either is fine (you can have a redirect for 1 too). The most important thing is just not to be ambiguous. And you should probably do redirects.
> 3) Serve identical content for "/foo" and "/foo/".
Not uncommon but VERY BAD. Don't even consider doing this.
> 4) Serve different content for "/foo" and "/foo/".
Uncommon BUT ALSO BAD. Zope 2, in a fit of cleverness, does this -- adding <base href> to one of those so the links work equivalently for either. It's a horrible awful thing. Resources and URLs should be one-to-one. Ambiguous URLs are one of those things in Zope that have scarred me, and seeing how hard that makes other things has made me sensitive to ambiguity elsewhere.
Directories in URLS should ALWAYS have / at the end. That prevents a
lot of confusion
as well as help the web/app server that analyzes the URL to determine
the proper prefixes.
For example, to match anything under /static directory, you need to
use a prefix pattern
"/static/" and not simply "/static" otherwise URLs such as /static1
will also match.
The problem is that the URL /static will not match the pattern "/
static/", so that's why you
always want your generated URLs to have a / after EACH directory in
the URL.
The only case you don't control is when the user goes to the root page
of your domain (e.g. www.mysite.com)
but luckily in that case the web server will treat this URLs path info
as "/"
On Nov 19, 9:05 am, "Mike Orr" <sluggos...@gmail.com> wrote:
> On Wed, Nov 19, 2008 at 7:28 AM, Raoul Snyman <raoul.sny...@gmail.com> wrote:
> > Hi all,
> > I'm attempting to upgrade my Pylons app to 0.9.7, but I can't seem to
> > get past the "302 you will now be redirected" problem.
> > What I did was I created a totally new Pylons app, and then I started
> > moving my controllers and models and things across. I'm not sure if
> > this is the best way, but I figured it was most probably the easiest.
> > I also read through the "What's new in 0.9.7" document and the
> > "Upgrading" document on the wiki, and followed directions as much as I
> > could.
> > I've left map.minimize on False, and I added the extra lines in my
> > routes.py file as per the documentation. I also made sure that my
> > middleware.py file had the necessary lines. I also modified base.py
> > and the BaseController class, because my authentication system checks
> > for a valid user in the __before__ function.
> > Now the problem comes in that when I hit the main page, my default
> > controller sees that there's no user logged in and tries to redirect
> > me to the login page. Except it just sits there saying "302 Found The
> > resource was found athttp://localhost:5000/member/login/;you should
> > be redirected automatically." and never redirects me.
> I have a similar authentication system in a Pylons 0.9.7 app so I can
> verify it works.
> Looking at your modules, I didn't know Routes had an .append_slash
> option but that could be throwing it off. There's no reason to put
> slashes at the end of URLs except to make it look like a directory to
> the user, but even then it's not necessary (/messages and
> /messages/1234 work fine).
> There's another redirect_to function in pylons.controllers.util which
> you should be using instead, as routes.redirect_to is being phased
> out. But they should both behave the same.
> You should be putting h.url_for() around all URLs, as that will adjust
> the URL if it needs a prefix someday. Or you can use Pylons 0.9.7's
> fancy url() object (pylons.url), which will be its replacement in
> Pylons 1.0.
> You can turn on route debugging to see if it gives any clues. Add
> this to development.ini:
> And add 'routes' to the 'keys' option in [loggers].
> If none of these help, I would check your app under Live HTTP Headers
> to see what it's actually doing. The 302 response should have a
> Location: header with the absolute URL to redirect to.