0

So I have the url:

url(r'^mousesmall/(?P<name>.*)/$', IDView.as_view()),

and my view is:

class IDView(DetailView):
    model = RNA
    template_name = "home/details.html"

Since I'm using the generic view detailview, how would I pass the name value that's captured in the URL to my detail view?

1 Answer 1

1

The base View class that DetailView inherits from sets the args and kwargs to self.args and self.kwargs respectively early in the processing. Since it's a named pattern, it should be in self.kwargs['name'].

Sign up to request clarification or add additional context in comments.

4 Comments

I get name 'self' is not defined.
Where are you trying to access the parameter? self should definitely be defined inside the view methods - unless you've declared them differently, which would generally be a bad idea.
I'm trying to access it within the view, I've added "target_id = self.kwargs['name']" right below my template_name code above.
That's not how it works - that would be setting a class-level definition. Instead, use it in your get method - or if you're just planning to display it in your template, the get_context_data method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.