views:

334

answers:

2

I have a form that and after the user fills in this form, I want to redirect to a URL that looks something like this

r'^user/(?P<id>\d+)/$'

The <id> is the primary key in the database...how do I go about this coz I'm stuck at this point

+1  A: 

Ok, so in your .html file, you should have an action= in your form, which sort of looks like that regular expression. At the very least it should look something similar to:

action="/user/{{ object.id }}/"

object.id would be replaced with whatever object you passed to the html file in your view.

AlbertoPL
sweet...let me try that. Thanks
seems like my view doesn't get the id at all...it just redirects to /user//
Are you redirecting to the page from one of your view functions using render_to_response? If so, you need to pass a dictionary of values. The object's id will need to be one of those.
AlbertoPL
think I've identified my problem...your solution should not work. Thnx
take the space out from between /user/ and {{ object.id }}.
Technical Bard
woops, thank you Technical Bard. Didn't even notice that.
AlbertoPL
+1  A: 

The url template tag allows you to save some repetition here. It also prevents you from breaking the form if you change urls.py. If your urlpattern looks like this:

(r'^user/(?P<id>\d+)/$', 'user.views.detail')

Then you could use the template tag like this:

<form action="{% url user.views.detail object.id %}">
iconoplast