Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Nov. 19, 2005 07:41:54

Bryan M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

urlpattern help


How do you write a urlpattern to match something like this:

/accounts/login/?next=/add_object/

?

I have this:

r'^accounts/login/\?next=(?P<next>.*)$'

and it seems to match because my view function is called, but no next
parameter is passed in. Oh wait, it's actually matching the previous
urlpattern:

r'^accounts/login/$'

Shouldn't the $ at the end prevent a string with stuff after the
'login/' from matching that one? When I do this in a python shell:

match = re.compile( r'^accounts/login/$' ).search(
'accounts/login/?next=/add_object/' )

match is None. When I do this:

match = re.compile( r'^accounts/login/\?next=(?P<next>.*)$' ).search(
'accounts/login/?next=/add_object/' )

match is not None and match.group('next') == '/add_object/'

What gives?

Bryan

Offline

#2 Nov. 19, 2005 08:13:16

Sune K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

urlpattern help


On 11/19/05, Bryan Murdock <> wrote:
> How do you write a urlpattern to match something like this:
>
> /accounts/login/?next=/add_object/

The parameters are not matched against the url patterns, in
your view-func you can get it as request.GET.

/s

Offline

#3 Nov. 19, 2005 15:09:44

Jeffrey E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

urlpattern help


Sune is correct--your problem stems from a misunderstanding of what aURL really is :) Anything after a '?' character is not truly part ofthe URL, but instead defines GET parameters which are sent to theresulting view.In other words, a URL (Universal Resource Locator) defines thelocation of a resource; when you send a URL to a Web server you'rerequesting the resource that exists at that location, and the GET key/value pairs which follow after a '?' are only ways to parameterizethat request--they do not change which resource is being requested.Therefore, from a URLpattern's point of view, "r'^accounts/login/$'"does indeed match the URL '/accounts/login/?next=/add_object/', andattempting to do URL matching against URLs with '?' in them will notdo you much good!If you can give us more info on what you're trying to do with the '?next=/whatever/' we might be able to give you tips on a moreefficient way of doing it, with regards to Django URLconfs :)Regards,
Jeff


On Nov 19, 2005, at 3:13 AM, Sune Kirkeby wrote:On 11/19/05, Bryan Murdock <> wrote:How do you write a urlpattern to match something like this:

/accounts/login/?next=/add_object/The parameters are not matched against the url patterns, in
your view-func you can get it as request.GET.

/s--
Jeffrey E. Forcier
Junior Developer, Research and Development
Stroz Friedberg, LLC
15 Maiden Lane, 12th Floor
New York, NY 10038
212-981-6540 212-981-6546http://www.strozllc.comThis message is for the named person's use only. It may contain
confidential, proprietary or legally privileged information. No right to
confidential or privileged treatment of this message is waived or lost
by any error in transmission. If you have received this message in
error, please immediately notify the sender by e-mail or by telephone at
212.981.6540, delete the message and all copies from your system and
destroy any hard copies. You must not, directly or indirectly, use,
disclose, distribute, print or copy any part of this message if you are
not the intended recipient.

Offline

#4 Nov. 19, 2005 15:21:35

Bryan M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

urlpattern help


On 11/19/05, Jeffrey E. Forcier <> wrote:
>
> Sune is correct--your problem stems from a misunderstanding of what a
> URL really is :) Anything after a '?' character is not truly part of
> the URL, but instead defines GET parameters which are sent to the
> resulting view.
>
> In other words, a URL (Universal Resource Locator) defines the
> location of a resource; when you send a URL to a Web server you're
> requesting the resource that exists at that location, and the GET key/
> value pairs which follow after a '?' are only ways to parameterize
> that request--they do not change which resource is being requested.
>
> Therefore, from a URLpattern's point of view, "r'^accounts/login/$'"
> does indeed match the URL '/accounts/login/?next=/add_object/', and
> attempting to do URL matching against URLs with '?' in them will not
> do you much good!
>
> If you can give us more info on what you're trying to do with the '?
> next=/whatever/' we might be able to give you tips on a more
> efficient way of doing it, with regards to Django URLconfs :)

And so it becomes very obvious that I'm new to this whole web
programming thing. Thank you for your patient explanations!

What am I doing? I'm just trying to make use of the @login_required decorator:http://www.djangoproject.com/documentation/authentication/#the-login-required-decoratorI'm hoping it'll be much easier now that you've explained the error of
(at least one of) my ways :-)

Bryan

Offline

#5 Nov. 19, 2005 15:48:40

Jeffrey E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

urlpattern help


On Nov 19, 2005, at 10:21 AM, Bryan Murdock wrote:And so it becomes very obvious that I'm new to this whole web
programming thing. Thank you for your patient explanations!No problem =) I just hope I didn't come across as condescending.What am I doing? I'm just trying to make use of the@login_required decorator:http://www.djangoproject.com/documentation/authentication/#the-login-required-decoratorI'm hoping it'll be much easier now that you've explained the error of
(at least one of) my ways :-)

BryanAh, I see now (don't use the auth stuff much yet, so I hadn't runacross that particular example). In that case, then hopefully myexplanation might lead you to the correct path of action--just ignorethat aspect of the login decorator entirely, at least with regards toyour URLconfs.Regards,
Jeff

--
Jeffrey E. Forcier
Junior Developer, Research and Development
Stroz Friedberg, LLC
15 Maiden Lane, 12th Floor
New York, NY 10038
212-981-6540 212-981-6546http://www.strozllc.comThis message is for the named person's use only. It may contain
confidential, proprietary or legally privileged information. No right to
confidential or privileged treatment of this message is waived or lost
by any error in transmission. If you have received this message in
error, please immediately notify the sender by e-mail or by telephone at
212.981.6540, delete the message and all copies from your system and
destroy any hard copies. You must not, directly or indirectly, use,
disclose, distribute, print or copy any part of this message if you are
not the intended recipient.

Offline

#6 Nov. 19, 2005 18:22:43

Adrian H.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

urlpattern help


On 11/19/05, Bryan Murdock <> wrote:
> And so it becomes very obvious that I'm new to this whole web
> programming thing. Thank you for your patient explanations!

Hey Bryan,

Thank *you* for asking the question! I've updated the tutorial and
URLconf documents so that they mention this explicitly.http://www.djangoproject.com/documentation/url_dispatch/http://www.djangoproject.com/documentation/tutorial3/Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org

Offline

#7 Nov. 19, 2005 20:39:01

Bryan M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

urlpattern help


On 11/19/05, Adrian Holovaty <> wrote:
>
> On 11/19/05, Bryan Murdock <> wrote:
> > And so it becomes very obvious that I'm new to this whole web
> > programming thing. Thank you for your patient explanations!
>
> Hey Bryan,
>
> Thank *you* for asking the question! I've updated the tutorial and
> URLconf documents so that they mention this explicitly.
>
>http://www.djangoproject.com/documentation/url_dispatch/>http://www.djangoproject.com/documentation/tutorial3/You are welcome! That's a nice addition to the docs.

Gee, just by asking my dumb questions I become a contributor :-)

Bryan

Offline

Board footer

Moderator control

Enjoy the 18th of November
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support