title: django.urls.exceptions.NoReverseMatch: Reverse for '' not found. '' is not a valid view function or pattern name
body: <p>I am trying to create a url-shohrtener and it gives me this error:</p>
  <blockquote>
  <p>django.urls.exceptions.NoReverseMatch: Reverse for '' not found. '' is not a valid view function or pattern name.</p>
  </blockquote>
  <pre><code>from django.contrib import admin
  from django.urls import path, include
  
  urlpatterns = [
      path('admin/', admin.site.urls),
      path('', include('shorturl.urls')),
  ]
  </code></pre>
  <p>here is my apps urls.py:</p>
  <pre><code>from django.urls import path
  from . import views
  
  urlpatterns = [
      path('', views.index, name='index'),
      path('&lt;str:id&gt;/', views.redirect_url, name='redirect'),
  ]
  </code></pre>
  <p>these are the views.py:</p>
  <pre><code>from django.shortcuts import render, redirect
  from .models import Url
  import random
  import string
  
  def redirect_url(request, id):
      urls = Url.objects.filter(short=id)
      link = &quot;&quot;
      for i in urls:
          link = i.url
      return redirect(link)
  
  def index(request):
      if request.method == &quot;POST&quot;:
          link = request.POST.get(&quot;link&quot;)
          short = &quot;&quot;
          if Url.objects.filter(url=link).exists():
              urls = Url.objects.all()
              for i in urls:
                  if i.url == link:
                      short = i.short
                      break
          else:    
              short = get_short_code()
              url = Url(url=link, short=short)
              url.save()
          new_url = request.get_host() + &quot;/&quot; + short
          return render(request, 'shorturl/index.html', {&quot;new_url&quot;:new_url})
  
      return render(request, 'shorturl/index.html')
  
  def get_short_code():
      length = 6
      char = string.ascii_uppercase + string.digits + string.ascii_lowercase
      while True:
          short_id = ''.join(random.choice(char) for x in range(length))
          if Url.objects.filter(short=short_id).exists():
              continue
          else:
              return short_id 
  </code></pre>
  <p>just in case it is important this is the template:</p>
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang=&quot;en&quot;&gt;
    &lt;head&gt;
      &lt;!-- Required meta tags --&gt;
      &lt;meta charset=&quot;utf-8&quot;&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
  
      &lt;!-- Bootstrap CSS --&gt;
      &lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; integrity=&quot;sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1&quot; crossorigin=&quot;anonymous&quot;&gt;
  
      &lt;title&gt;Shroten URL&lt;/title&gt;
      &lt;script&gt;
        function myFunction() {
          /* Get the text field */
          var copyText = document.getElementById(&quot;myInput&quot;);
  
          /* Select the text field */
          copyText.select();
          copyText.setSelectionRange(0, 99999); /* For mobile devices */
  
          /* Copy the text inside the text field */
          document.execCommand(&quot;copy&quot;);
        }
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
  
      &lt;div class=&quot;container&quot; style=&quot;padding-top: 5%;&quot;&gt;
          &lt;form method=&quot;POST&quot;&gt;
              {% csrf_token %}
              &lt;div class=&quot;mb-3&quot;&gt;
              &lt;label for=&quot;exampleInputEmail1&quot; class=&quot;form-label&quot;&gt;Link&lt;/label&gt;
              &lt;input name=&quot;link&quot; type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;exampleInputEmail1&quot; aria-describedby=&quot;emailHelp&quot;&gt;
              &lt;/div&gt;
              &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Shorten&lt;/button&gt;
          &lt;/form&gt;
          {% if new_url %}
            &lt;div class=&quot;mb-3&quot;&gt;
              &lt;label for=&quot;exampleInputEmail1&quot; class=&quot;form-label&quot;&gt;Short Link&lt;/label&gt;
              &lt;input name=&quot;link&quot; type=&quot;text&quot; value= {{new_url}} class=&quot;form-control&quot; id=&quot;myInput&quot; aria-describedby=&quot;emailHelp&quot;&gt;
            &lt;/div&gt;
            &lt;button onclick=&quot;myFunction()&quot; class=&quot;btn btn-primary&quot;&gt;COPY&lt;/button&gt;
            
          {% endif %}
      &lt;/div&gt;
      &lt;!-- Optional JavaScript; choose one of the two! --&gt;
  
      &lt;!-- Option 1: Bootstrap Bundle with Popper --&gt;
      &lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js&quot; integrity=&quot;sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
  
      &lt;!-- Option 2: Separate Popper and Bootstrap JS --&gt;
      &lt;!--
      &lt;script src=&quot;https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js&quot; integrity=&quot;sha384-q2kxQ16AaE6UbzuKqyBE9/u/KzioAlnx2maXQHiDX9d4/zp8Ok3f+M7DPm+Ib6IU&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.min.js&quot; integrity=&quot;sha384-pQQkAEnwaBkjpqZ8RU1fF1AKtTcHJwFl3pblpTlHXybJjHpMYo79HY3hIi4NKxyj&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
      --&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>The error I'm getting just on the terminal the website works fine.
  The whole error is:</p>
  <pre><code>Traceback (most recent call last):
  
  File
  &quot;C:\Users\Dell\Desktop\new\xp\lib\site-packages\django\core\handlers\exception.py&quot;,
  line 47, in inner
      response = get_response(request)   File &quot;C:\Users\Dell\Desktop\new\xp\lib\site-packages\django\core\handlers\base.py&quot;,
  line 181, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)   File &quot;C:\Users\Dell\Desktop\new\xp\Url-shortener\shorturl\views.py&quot;, line
  12, in redirect_url
      return redirect(link)   File &quot;C:\Users\Dell\Desktop\new\xp\lib\site-packages\django\shortcuts.py&quot;,
  line 41, in redirect
      return redirect_class(resolve_url(to, *args, **kwargs))   File &quot;C:\Users\Dell\Desktop\new\xp\lib\site-packages\django\shortcuts.py&quot;,
  line 131, in resolve_url
      return reverse(to, args=args, kwargs=kwargs)   File &quot;C:\Users\Dell\Desktop\new\xp\lib\site-packages\django\urls\base.py&quot;,
  line 87, in reverse
      return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))   File &quot;C:\Users\Dell\Desktop\new\xp\lib\site-packages\django\urls\resolvers.py&quot;,
  line 685, in _reverse_with_prefix
      raise NoReverseMatch(msg) django.urls.exceptions.NoReverseMatch: Reverse for '' not found. '' is not a valid view function or pattern
  name.
  </code></pre>
  <p>Please help me solve this problem.</p>