Created
January 21, 2012 01:01
-
-
Save sleekslush/1650547 to your computer and use it in GitHub Desktop.
Slug field name example with DetailView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# urls.py | |
urlpatterns = patterns('', | |
url(r'^something/(?P<slug>\d+)/$', MyView.as_view()), | |
) | |
# views.py | |
class MyView(DetailView): | |
slug_field = 'my_cool_field' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how do you invoke the get_absolute_url in the list view?
my model has this get_absolute_url:
def get_absolute_url(self):
return reverse('blog:detail', kwargs= {'slug': self.title})
my urls.py:
url(r'^(?P[-\w]+)/$', PostDetailView.as_view(), name='detail'),
and my views.py:
class PostDetailView(LoginRequiredMixin, DetailView):
model = Post
template_name = 'blog/details.html'
form_class = CommentForm
slug_field = 'title'
slug_url_kwarg = 'slug'
so in the list template, i invoke the get_absolute_url like this:
{{ articles.get_absolute_url }}
and also tried:
{% url 'blog:detail' articles.title %}
it gives the same error as:
NoReverseMatch at /blog/
Reverse for 'detail' with arguments '('Hello Third',)' not found. 1 pattern(s) tried: ['blog/(?P[-\w]+)/$']
pls help me, guys