Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django url pattern matching

I've been over this for too many hours now and I cannot see anymore what I'm doing wrong:

url(r'^baz/([a-z0-9]+)/([a-z0-9]+)/[0-9]/$', 'foobar.views.baz')

def baz(request, xxx, yyy, zzz):
    pass

And this is the actual URL being requested:

http://localhost:8000/baz/75ca0f5bf13d67895e23419c25f82e87f3f5f95f/f733dbf686cd51f911e533d5a351f81394c9db5c/0/

Django keeps throwing this error at me:

baz() takes exactly 4 arguments (3 given)

What am I doing wrong?

like image 945
Lorenzo Avatar asked Jul 02 '26 00:07

Lorenzo


1 Answers

You're missing the last block of parens in your regular expression.

url(r'^baz/([a-z0-9]+)/([a-z0-9]+)/([0-9])/$', 'foobar.views.baz')

With the parens Python will capture the [0-9] as a group and now you'll get all 3 parameters (+ the self) instead of 2.

like image 169
Matthias Avatar answered Jul 03 '26 15:07

Matthias



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!