HI daniel, thanks for the reply After your comments, I have used ModelForm to simplify my code. I have also achieved redirecting the desired url by using the redirect() function. My issues are still basically the same however:
- I do not know how to tell Django to render a template at the redirected url. I've tried passing redirect differnt views and params etc. to no avail. Here is my new views.py: http://dpaste.org/EtxdP/ I am trying to have the event_page view handle the redirect and render the template it returns. I know I am not relating the redirect and the view at all, this is because I do not know how. If I try to relate them in some way like this: return redirect('event_page', event) I get the error: Reverse for 'event_page' with arguments '(<Event: pppzzz>,)' and keyword arguments '{}' not found. My urls.py looks like this now: http://dpaste.org/UzBcR/ I am sort of hazy on the use of the third parameter in my second url pattern. I know the first param is a regex, the second is the view that handles the url, and from what I understand by reading the docs, the third param is a type of distinguisher used if you are calling the same view for different urls. Any thoughts on where I would begin to for rendering a template at the redirected url? Thanks, Matt On Wednesday, July 25, 2012 6:29:42 AM UTC-4, Daniel Roseman wrote: > > > > On Wednesday, 25 July 2012 02:42:45 UTC+1, Matthew Meyer wrote: >> >> Hello all, >> >> I'm trying to load the url of a model created with get_absolute_url() >> programmatically in my view. There are basically three steps I need to >> accomplish this: >> >> 1. make sure @permalink is working correctly. This step I am fairly >> confident I have completed. Here is the model I use: >> http://dpaste.org/nH0cZ/ >> >> 2. make sure I am rendering the url correctly in my view: >> http://dpaste.org/FOGjs/ >> >> This view is fairly involved. The return statement on line 12 is where I >> am trying to load the url. In a nutshell, if the request is GET this view >> renders a form for the user which they can use to fill some fields in a >> model. one of the fields they fill ("name") I want to use as my the >> rendered url, which is why I am trying to pass {'event': Event} on line >> 12 when request.method == 'POST' and the user has submitted the form. >> Right now when the user submits the post, the event_page.hml loads but >> without the event object url. >> >> 3. make sure my urlconfs are working:: http://dpaste.org/LPdfK/ Not >> positive here, but I know this is fairly simple to most. I just tried to >> follow what the docs had for get_absolute_url and @permalink ( >> https://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs#django.db.models.permalink) >> >> Something is wrong though because the "view on website" button in admin is >> leading to a permalinked url that doesn't match. >> >> As you can see, I am quite a bit lost and could really use some guidance. >> Any help is appreciated. Thanks! >> > > > Your problem is in step 2. `Event` is the model class itself, but you want > to render the URL for a particular instance of that class. Presumably you > want the event that has been created by the form. I don't understand why > you are using a formset though: that implies you are creating multiple > events, whereas you talk about showing the URL for a single event, which > makes more sense. Sounds like you should use a simple ModelForm, and if > it's valid do `event = form.save()` - now you can pass that `event` object > to the template. > > Finally, note that rendering a template directly after a POST is a bad > idea, as the documentation explains. You should always redirect to a new > page: you could redirect directly to the new event's URL if you like. > -- > DR. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Ke1q_x6ak6wJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.