slug - when to store slugfield in database in django? -


suppose access article at

/article/23/the-46-year-old-virgin 

in /article/id/slug form.

i can use id fetch data in view.
don't see reason store slug in database.

besides, /article/id/slug isn't better /article/slug ?

the problem using id hurt both url readability , search engine optimization. (see here latter.)

one problem using slug long , urls truncated in real world. if have id @ beginning use lookups , redirect if went wrong slug part. other problem have guarantee slugs unique. sure you'll never want have 2 articles same title?

so doing 1 or other possible, there benefits doing both.

as whether or not should store slug in database, first decide if want url change when title changes. 1 advantage keeping same have single, permanent, canonical url resource, 1 won't change if need edit title. obvious downside url no longer reflect exact title of article.

if want slug match title, becomes standard database denormalization question - slug represent redundant (derived) information you're precomputing performance reasons. wouldn't bother, myself.

if want url stay same if title edited, of course have store slug separately.


Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -