views:

496

answers:

6

Hello,

My public template grabs data from Postgres to a drop down menu. The template displays the data in the drop down menu. When the selection is activated the following error occurs:

commodity() takes exactly 2 arguments (1 given)

The template code, views and URL are here:

http://dpaste.com/109411/

Thank you,

Ana

A: 

You forgot to add the regex in your url file

(r'^commodity/(\d+)$', 'commodity'),

See if this works.

Edit: check here for more examples http://docs.djangoproject.com/en/dev/topics/http/urls/#example

Tiago
A: 

Your commodity view is expecting an index and none is given in the url.

Change your url to:

(r'^commodity/(?P<commodity_id>\d+)$', 'commodity')

And trigger it using urls like:

http://localhost:8000/commodity/5

With 5 being the captured ID from the url.

Soviut
A: 

Thank you for all the help. At least the original error doesn't occur, but neither of the regular expressions worked. The error I received is now this:

The current URL, fsafety/commodity/, didn't match any of these. The these is this: ^fsafety/ ^commodity/(?P\d+)$

At least I know now, that the error is in the URL, but could it also be possible that the ID is not being passed from the form? The data doesn't present until after this statement in the form:

{% for commodity in commodity_list %}

Thank you, again!!

Ana

A: 

Your url should be:

^fsafety/commodity/(\d+)$

Or if you want an named expression:

^fsafety/commodity/(?P<commidity_id>\d+)$

You have two main problems. The first is your commodity_id group has to be either named or numbered. (?P<group_name_here>\d+) is a named group, while (\d+) is a numbered group and is captured based on order. Second, you need need to fully qualify your URLs unless you're using an include() command to include another Django app's urls.py file.

Soviut
"that stiff breeze you feel is regular expressions sucking" -- Tim Peters
Aaron Watters
A: 

Hi Ana,

I misread your initial post. Use the original regexp and remove the commodity_id parameter from the function.

now change this:

commodity_id = request.POST['commodity']

to that:

commodity_id = request.POST['commodity_id']

Now it should work.

Tiago
A: 

Thank you all for the help! I still can't get it to work, but at this point I'm going to start over again, fresh, taking your suggestions into account.

Thanks, again!

Ana