Thanks for the reply. Yes, I can give a bit more info on it.
So, for starters, my (abbreviated) main url conf looks like this:
urlpatterns = patterns('',
(r'^surveys/', include('servicetrac.surveys.urls')),
)
... which links over to the app's urls:
urlpatterns = patterns('servicetrac.surveys.views',
(r'^(?P<company_slug>[^/]+)/(?P<event_id>\d+)/web/take/(?
P<page>\d+)', 'take_survey', {
'name': 'this_is_a_name',
}),
(r'^(?P<company_slug>[^/]+)/(?P<event_id>\d+)/web/take',
'take_survey', {'page': 1}),
)
And the "take_survey" view signature:
take_survey(request, company_slug, event_id, page=1)
The default parameter for 'page' is a little redundant to what the
urls define, but it's self-documenting, in my mind.
So, up to this point, everything works as expected. Absolutely no
problems. The view works great, tested under both of the possible
urls to get there. But of course, I wanted to partake of the niceness
of having a "View on site ->" link on the admin page for the object,
so I began to implement the "get_absolute_url" method, employing the
decorator "models.permalink", as described previously:
# in my "Event" model
@models.permalink
def get_absolute_url(self):
return ('this_is_a_name', (), {
'company_slug': self.company.slug
'event_id': self.id
'page': 1
})
Now, my case doesn't seem too abnormal, but I find it difficult to
even track what happens after this. Using my wishful "View on site"
link yields the same result as calling the method in the manage.py
shell:
>>> event.get_aboslute_url()
Traceback (most recent call last):
................snip...............
NoReverseMatch: Reverse for 'this_is_a_name' with arguments '()' and
keyword arguments '{'event_id': 1L, 'company_slug': u'mycompany',
'page': 1}' not found.
Now, I've tried to simplify my task as much as possible, by naming the
view and everything. I thought maybe some funny-business was going on
with the optional parameter, but changes don't seem to make any
difference.
Any thoughts? I'm pretty sure there's no more info to give... the
full traceback stays in Django files, never directly touching my own,
and doesn't reveal anything more than I've posted.
Thanks,
Tim
On Nov 24, 8:52 pm, Karen Tracey <[email protected]> wrote:
> On Tue, Nov 24, 2009 at 4:49 PM, Tim Valenta
> <[email protected]>wrote:
>
>
>
>
>
> > Ever since day one, I've never had a firm grasp on what the heck URL
> > reversing can do. I understand the concepts involved, even the admin
> > namespacing that can occur with different admin sites, and I know that
> > the admin uses it regularly, but it seems like a crazy unpredictable
> > wildcard when I try to use it manually.
>
> > For instance, I'm trying to get the permalink decorator to work on a
> > "get_absolute_url()" method on my model, and I haven't got the
> > slightest clue what the hell it's doing. I'm getting errors about it
> > not being able to reverse it properly when I try to click on the admin-
> > generated "View on site ->" link from the change form. It says that
> > it can't find the view.
>
> > Basically, I've tried making the method refer to the view object, a
> > view name as a string (explicitly setting the name in the url conf),
> > an absolute module-path string ("myproject.myapp.views.my_view"), and
> > nothing works. It can never find it, even on a view with just a
> > single required keyword argument.
>
> > Is there any amazing breakdown on how to better wrap my brain around
> > how this url reversing thing works? I typically don't think of myself
> > as an idiot, but I really cannot even begin to feel like I can use it
> > proficiently.
>
> I could point you to the doc
> (http://docs.djangoproject.com/en/dev/ref/models/instances/#the-permal...)
> but it sounds like you have already read that.
>
> Alternatively I could try to explain the errors you are getting for the
> various things you have tried, but there aren't enough specifics here to do
> that. Spell out the URLConf info, exactly what you have tried for the
> permalink/ger_abosolute_url code, and exactly what the error is, and someone
> can likely help.
>
> I'm assuming you are getting NoReverseMatch and that's what you mean when
> you say "It says that it can't find the view"? Those can be frustrating to
> debug, but they tend be right and mean exactly what they say: given the
> URLConf in place, there is no URL pattern in there that would result in the
> specified view being called with the noted parameters. The trick then is to
> figure out why, since clearly you're expecting the URLConf to contain a
> pattern that would result in that view being called with those
> parameters....but without specifics on what you're trying it's hard to say
> what, exactly, is going wrong with what you are trying.
>
> Karen
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.