title: creating catch-all url() entry using regex
body: <p>So had zero issues with my Django and React URL routing in dev, but now that I am trying to move to production, running into all kinds of issues. </p>
  
  <p>Yes, I suck when it come to regex. It looks like a cat walked on a keyboard. Definitely something I need to sit down and commit to learning.</p>
  
  <p>In dev, my catch-all was just the following which worked perfectly:</p>
  
  <pre><code>url(r'', TemplateView.as_view(template_name='index.html')),
  </code></pre>
  
  <p>In production, I got <code>Uncaught SyntaxError: Unexpected token &lt;</code>. This, as it was explained to me, had to do with JS being caught in the url instead of <code>index.html</code> and that the JS  needed to "pass through". I was told to try:</p>
  
  <pre><code>url(r'^$', TemplateView.as_view(template_name='index.html')),
  </code></pre>
  
  <p>This worked. The web application loaded and I was able to navigate.</p>
  
  <p>Another problem came up, however, when it came to verification emails links. I am running into issues with <code>Page not found (404)</code> which, again, wasn't an issue in my dev setup.</p>
  
  <p>The email links look like the following:</p>
  
  <p><code>https://test.example.com/auth/security_questions/f=ru&amp;i=101083&amp;k=6d7cd2e9903232a5ac28c956b5eded86c8cb047254a325de1a5777b9cca6e537</code></p>
  
  <p>What I get back is this:</p>
  
  <p><code>Page not found (404)
  Requested URL: http://test.example.com/auth/security_questions/f%3Dru&amp;i%3D101083&amp;k%3D6d7cd2e9903232a5ac28c956b5eded86c8cb047254a325de1a5777b9cca6e537/</code></p>
  
  <p>My react routes are the following:</p>
  
  <pre><code>&lt;App&gt;
      &lt;Switch&gt;
          &lt;Route exact path='/auth/security_questions/f=:f&amp;i=:id&amp;k=:key' component={SecurityQuestions} /&gt;
          &lt;Route exact path='/auth/*' component={Auth} /&gt;
          &lt;Route exact path='/' component={Auth} /&gt;
      &lt;/Switch&gt;
  &lt;/App&gt;
  </code></pre>
  
  <p>This should render <code>/auth/security_questions/...</code> route. </p>
  
  <p>My <code>urls.py</code> is the following:</p>
  
  <pre><code>urlpatterns = [
      # API authentication entry point   
      url(r'^api/auth/', include('authentication.urls', namespace='signin')),
  
      # Any requets that come through serve the index.html
      # url(r'^$', TemplateView.as_view(template_name='index.html')),
  
  ] + static(settings.STATIC_URL, 
  document_root=settings.STATIC_ROOT)
  </code></pre>
  
  <p>Also, the <code>authentication.urls</code>:</p>
  
  <pre><code>urlpatterns = [
      url(r'^security_questions/', SecurityQuestionsAPIView.as_view(), name='security_questions'),
  ]
  </code></pre>
  
  <p>It seems like Django is trying to handle the routing, there obviously isn't a route that matches, when really it should just render <code>index.html</code> and let <code>react-router-dom</code> take over to send requests to the API from the FE. Thus, it seems I need to make a catch-all that lets JS through.</p>
  
  <p>I came across this question which seemed relevant: <a href="https://stackoverflow.com/questions/40826295/react-routing-and-django-url-conflict">react routing and django url conflict</a>. So I added the following so that I have a <code>/</code> catch and then "everything-else" catch-all.</p>
  
  <pre><code># match the root
  url(r'^$', TemplateView.as_view(template_name='index.html')),
  # match all other pages
  url(r'^(?:.*)/?$', TemplateView.as_view(template_name='index.html')),
  </code></pre>
  
  <p>Still won't render the verification links. Tried a few other variations for the last-catch all URL:</p>
  
  <p><a href="https://stackoverflow.com/questions/31248126/django-route-all-non-catched-urls-to-included-urls-py">Django route all non-catched urls to included urls.py</a></p>
  
  <p><code>url(r'^', TemplateView.as_view(template_name='index.html')),</code></p>
  
  <p>Results in <code>Uncaught SyntaxError: Unexpected token &lt;</code></p>
  
  <p><a href="https://stackoverflow.com/questions/28264061/django-catching-any-url">django catching any url?</a></p>
  
  <p><code>url(r'^.*', TemplateView.as_view(template_name='index.html')),</code></p>
  
  <p>See the preceding.</p>
  
  <p>So going to dig into Django, regex, and try to sort this out, but in the mean time...</p>
  
  <p><strong>What am I doing wrong here?</strong></p>