2👍
One of the things you are going to want to look into is a slugfield which will allow you to have data that is capable of being used in a url. Slugs can contain only letters, numbers, underscores or hyphens. From there you will most likely want to override your model’s save
method to set and ensure the slugfield is unique. You can then use that field as an identifier for your url. You can then do something like {% url 'blog:detail' slug=p.slug %}
assuming that you name the field slug
. Also, as pointed out in another answer, if you do use this, you need to fix your url to look for a slug instead.
urlpatterns = patterns ('',
url(r'^(?P<slug>[\w-]+)/$',
PostDetailView.as_view(),
name = 'detail'
),
)
0👍
If you’re using the generic detail view, it expects either an id or a slug value.
However, in your URL conf, you’re specifying the named variable as ‘title’. Try changing it to ‘slug’:
urlpatterns = patterns ('',
url(r'^(?P<slug>\w+)/$',
PostDetailView.as_view(),
name = 'detail'
),
)