Reputation: 1469
I have the follow url:
http://mywebsite.com/post/1/
url(r'^guideline/(\d+)/?(?:.json)?$', perma_post, name="cv_perma")
How can I add an string at the end to display the title of the post 1? For example
http://mywebsite.com/post/1/THIS-IS-JUST-THE-TITLE/
Upvotes: 0
Views: 224
Reputation: 552
The title in the URL is part of the pattern, which may or may not be matched against the document slug in the view.
Something like:
url(r'^guideline/(?P<id>\d+)/(?P<slug>[-\w]+)/$', perma_post, name="cv_perma")
Then you could look for an object with both id and slug, or just the id and redirect to the correct URL if the slug does not match -which is what Stackoverflow does.
Upvotes: 1