librelist archives

« back to archive

Problem with modules and urls...

Problem with modules and urls...

From:
Smartboy
Date:
2011-03-07 @ 15:29
Hello,

I'm developing my own custom CMS with Flask, and it was working up until 
I decided to split it into modules. Before, I had been using the 
following routes all in one file:
@app.route("/")
@app.route("/<path:pagename>")
@app.route("/login", methods=["POST"])
@app.route("/logout")
I had quickly decided that I was going to start it off by building it up 
using modules, though, so that I wouldn't have to have nightmares trying 
to get it working when the code was even larger. Unfortunately, though, 
it isn't working. I put the first two in a file called main.py 
underneath a views folder, and the last two in a file called 
authenticate.py under the same folder, and connected them in my 
application's __init__.py so that I have:
app.register_module(authenticate, url_prefix='/authenticate')
app.register_module(main) # also tried reversing the order, didn't help
The problem is that main.py's /<path:pagename> seems to be overriding 
everything else, while it wasn't when it was all in one file. Is there 
any way to get around this? And before anyone asks why, it is because I 
want to check whether a page is in a database or not before I give a 
page not found error.

Thanks to the creators of Flask, and to whomever helps,
Smartboy

Re: [flask] Problem with modules and urls...

From:
Adam Patterson
Date:
2011-03-07 @ 16:20
You mentioned that you tried reversing the order but it definitely
sounds like /<path:pagename> rule is before the others. That rule will
match pretty much anything (including /authiticate/login, etc) so it
definitely has to happen last.

On Mon, Mar 7, 2011 at 9:29 AM, Smartboy <smartboyathome@gmail.com> wrote:
> Hello,
>
> I'm developing my own custom CMS with Flask, and it was working up until
> I decided to split it into modules. Before, I had been using the
> following routes all in one file:
> @app.route("/")
> @app.route("/<path:pagename>")
> @app.route("/login", methods=["POST"])
> @app.route("/logout")
> I had quickly decided that I was going to start it off by building it up
> using modules, though, so that I wouldn't have to have nightmares trying
> to get it working when the code was even larger. Unfortunately, though,
> it isn't working. I put the first two in a file called main.py
> underneath a views folder, and the last two in a file called
> authenticate.py under the same folder, and connected them in my
> application's __init__.py so that I have:
> app.register_module(authenticate, url_prefix='/authenticate')
> app.register_module(main) # also tried reversing the order, didn't help
> The problem is that main.py's /<path:pagename> seems to be overriding
> everything else, while it wasn't when it was all in one file. Is there
> any way to get around this? And before anyone asks why, it is because I
> want to check whether a page is in a database or not before I give a
> page not found error.
>
> Thanks to the creators of Flask, and to whomever helps,
> Smartboy
>

Re: [flask] Problem with modules and urls...

From:
Smartboy
Date:
2011-03-07 @ 16:56
Well, as you can see, main is being loaded last, and /<path:pagename> is 
being loaded last within main, but still I can't access 
/authenticate/logout (it gives me my error page).

Smartboy

On 03/07/2011 08:20 AM, Adam Patterson wrote:
> You mentioned that you tried reversing the order but it definitely
> sounds like /<path:pagename>  rule is before the others. That rule will
> match pretty much anything (including /authiticate/login, etc) so it
> definitely has to happen last.
>
> On Mon, Mar 7, 2011 at 9:29 AM, Smartboy<smartboyathome@gmail.com>  wrote:
>> Hello,
>>
>> I'm developing my own custom CMS with Flask, and it was working up until
>> I decided to split it into modules. Before, I had been using the
>> following routes all in one file:
>> @app.route("/")
>> @app.route("/<path:pagename>")
>> @app.route("/login", methods=["POST"])
>> @app.route("/logout")
>> I had quickly decided that I was going to start it off by building it up
>> using modules, though, so that I wouldn't have to have nightmares trying
>> to get it working when the code was even larger. Unfortunately, though,
>> it isn't working. I put the first two in a file called main.py
>> underneath a views folder, and the last two in a file called
>> authenticate.py under the same folder, and connected them in my
>> application's __init__.py so that I have:
>> app.register_module(authenticate, url_prefix='/authenticate')
>> app.register_module(main) # also tried reversing the order, didn't help
>> The problem is that main.py's /<path:pagename>  seems to be overriding
>> everything else, while it wasn't when it was all in one file. Is there
>> any way to get around this? And before anyone asks why, it is because I
>> want to check whether a page is in a database or not before I give a
>> page not found error.
>>
>> Thanks to the creators of Flask, and to whomever helps,
>> Smartboy
>>

Re: [flask] Problem with modules and urls...

From:
Drew Vogel
Date:
2011-03-08 @ 13:48
On Mon, Mar 7, 2011 at 10:56 AM, Smartboy <smartboyathome@gmail.com> wrote:

> Well, as you can see, main is being loaded last, and /<path:pagename> is
> being loaded last within main, but still I can't access
> /authenticate/logout (it gives me my error page).
>
>
One work-around would be to mount the pagename route on /page.

Drew Vogel

Re: [flask] Problem with modules and urls...

From:
Smartboy
Date:
2011-03-08 @ 15:56
On 03/08/2011 05:48 AM, Drew Vogel wrote:
> On Mon, Mar 7, 2011 at 10:56 AM, Smartboy <smartboyathome@gmail.com 
> <mailto:smartboyathome@gmail.com>> wrote:
>
>     Well, as you can see, main is being loaded last, and
>     /<path:pagename> is
>     being loaded last within main, but still I can't access
>     /authenticate/logout (it gives me my error page).
>
>
> One work-around would be to mount the pagename route on /page.
>
> Drew Vogel
Yes, if I wanted everyone to go to /page/*. That would be a workaround 
though I'd prefer to keep it the way it is now. if all else fails I'll 
just keep using my combined script and separate the display functions 
into separate files since that seems to work.

Smartboy