title: Django Rest Framework how to return detail not found on all invalid urls?
body: <p>Django 1.7</p>
  
  <p>DRF 3.3.2</p>
  
  <p>Python 2.7</p>
  
  <p>I want to return a 404 Response with <code>{'detail': 'Not found'.}</code> whenever I  enter an invalid url.</p>
  
  <p>However I get this only when I enter a valid url with invalid lookup parameters.</p>
  
  <p>For example, if I make a GET request on:</p>
  
  <p><a href="http://127.0.0.1:8000/api/boxes/3e1659f3-9238-4b8f-a580-9b096d95bbfa/" rel="nofollow noreferrer">http://127.0.0.1:8000/api/boxes/3e1659f3-9238-4b8f-a580-9b096d95bbfa/</a></p>
  
  <p>i will get the requested object.</p>
  
  <p>If I do the same thing with:</p>
  
  <p><a href="http://127.0.0.1:8000/api/boxes/3e1659f3-9238-4b8f-a580-9b096d95bbfajibbersihherelalalalalalala/" rel="nofollow noreferrer">http://127.0.0.1:8000/api/boxes/3e1659f3-9238-4b8f-a580-9b096d95bbfajibbersihherelalalalalalala/</a></p>
  
  <p>I will get a 404 with <code>{'detail': 'Not found'.}</code> message in the body.</p>
  
  <p>If i try the same thing with this url:</p>
  
  <p><a href="http://127.0.0.1:8000/api/boxesevenbiggerjibberish" rel="nofollow noreferrer">http://127.0.0.1:8000/api/boxesevenbiggerjibberish</a></p>
  
  <p>I will get a 404 with this error:</p>
  
  <p><a href="https://i.stack.imgur.com/V2f7f.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V2f7f.jpg" alt="enter image description here"></a></p>
  
  <p>which will break my app.</p>
  
  <p>So the question is, how do I set up my urls so that every invalid url is handled with the <code>{'detail': 'Not found'.}</code> message (which won't break my app).</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The given answer will set a custom 404 view for your entire project (all aps).</p>
  
  <p>If you want to set a custom 404 for a particular app inside a project, (e.g. you want your API to return json, but you want your app to return some custom template), then you can set a urlpattern to catch everything:</p>
  
  <p>myapp/urls.py</p>
  
  <pre><code>urlpatterns = [
      ...,
      ...,
      url(r'^.*/$', views.error_page, name='error_page')
  ]
  </code></pre>
  
  <p>Make sure that the url is the last pattern (otherwise every url will call your custom error_page view).</p>