title: Django - URL design and best practices for identify one object
body: <p>Im actually working in a django project and I'm not sure about the best format of the URL to access into one particular object page.</p>
  
  <p>I was thinking about these alternatives:</p>
  
  <pre><code>1) Using the autoincremental ID =&gt; .com/object/15
  </code></pre>
  
  <p>This is the simplest and well known way of do that. "id_object" is the autoincremental ID generated by the database engine while saving the object. The problem I find in this way is that the URLs are simple iterable. So we can make an simple script and visit all the pages by incrementing the ID in the URL. Maybe a security problem.</p>
  
  <pre><code>2) Using a &lt;hash_id&gt; =&gt; .com/object/c30204225d8311e185c3002219f52617
  </code></pre>
  
  <p>The "hash_id" should be some alphanumeric string value, generated for example with uuid functions. Its a good idea because it is not iterable. But generate "random" uniques IDs may cause some problems.</p>
  
  <pre><code>3) Using a Slug =&gt; .com/object/some-slug-generated-with-the-object
  </code></pre>
  
  <p>Django comes with a "slug" field for models, and it can be used to identify an object in the URL. The problem I find in this case is that the slug may change in the time, generating broken URLs. If some search engine like Google had indexed this broken URL, users may be guided to "not found" pages and our page rank can decrease. Freezing the Slug can be a solution. I mean, save the slug only on "Add" action, and not in the "Update" one. But the slug can now represent something old or incorrect.</p>
  
  <p>All the options have advantages and disadvantages. May be using some combination of them can some the problems.
  What do you think about that?</p>