title: Reverse for 'book-detail' with arguments '('',)' not found. 1 pattern(s) tried: ['catalog/book/(?P<pk>[0-9]+)$']
body: <p>My website is working well on my local environment, as well as it has been working well on heroku env until my recent deployment.
  Code is same on both environments and I referred to all 11 posts related to similar issue,example <a href="https://stackoverflow.com/questions/55302876/reverse-for-todo-user-with-arguments-not-found-1-patterns-tried">Reverse for &#39;todo-user&#39; with arguments &#39;(&#39;&#39;,)&#39; not found. 1 pattern(s) tried</a></p>
  
  <p>My issue looks different than what I have seen in other posts here, I think it is related to environment settings/variables, which I am not able to identify it yet.
  But the solutions provided on stack overflow, makes me think like the real problem of this issue is something else.</p>
  
  <p>When I try to click on <a href="http://127.0.0.1:8000/catalog/mybooks/" rel="nofollow noreferrer">http://127.0.0.1:8000/catalog/mybooks/</a> link, local website works fine, however, production (heroku), same code throws following exception</p>
  
  <hr>
  
  <pre><code>NoReverseMatch at /catalog/mybooks/
  Reverse for 'book-detail' with arguments '('',)' not found. 1 pattern(s) tried: ['catalog/book/(?P&lt;pk&gt;[0-9]+)$']
  Request Method: GET
  Request URL:    https://&lt;myapp&gt;.herokuapp.com/catalog/mybooks/
  Django Version: 2.2.5
  Exception Type: NoReverseMatch
  Exception Value:    
   Reverse for 'book-detail' with arguments '('',)' not found. 1 pattern(s) tried: ['catalog/book/(?P&lt;pk&gt;[0-9]+)$']
   Exception Location:    /app/.heroku/python/lib/python3.7/site-packages/django/urls/resolvers.py in _reverse_with_prefix, line 673
   Python Executable: /app/.heroku/python/bin/python
   Python Version:    3.7.3
   Python Path:   
  ['/app/.heroku/python/bin',
   '/app',
   '/app/.heroku/python/lib/python37.zip',
   '/app/.heroku/python/lib/python3.7',
   '/app/.heroku/python/lib/python3.7/lib-dynload',
   '/app/.heroku/python/lib/python3.7/site-packages']
   Server time:   Wed, 9 Oct 2019 04:52:47 +0000
   Error during template rendering
   In template /app/catalog/templates/base_generic.html, error at line 7
   Reverse for 'book-detail' with arguments '('',)' not found. 1 pattern(s) tried: ['catalog/book/(?P&lt;pk&gt;[0-9]+)$']
  </code></pre>
  
  <hr>
  
  <p>This looks like a misleading error to me.</p>
  
  <p>Also, because the code is working as expected on my local (ie, showing me all the data), so it doesn't look like a coding issue and so I am not able to understand real problem here (and provided solutions for other similar issues)</p>
  
  <hr>
  
  <p><strong>I have applied all migrations, so environment looks okay:</strong> </p>
  
  <pre><code>$ heroku run python manage.py migrate --remote heroku-prod
   Running python manage.py migrate on &lt;my app&gt;... starting, run.5216 (Free)
   Running python manage.py migrate on &lt;my app&gt;... connecting, run.5216 (Free)
   Running python manage.py migrate on &lt;my app&gt;... up, run.5216 (Free)
   Operations to perform:
    Apply all migrations: admin, auth, catalog, contenttypes, sessions, social_django
   Running migrations:
    No migrations to apply.
  
  HP@HP-PC MINGW64 ~/git_projects/prod/django_local_library (master)
  </code></pre>
  
  <hr>
  
  <p><em>Code on DEV/staging, that is also same.</em></p>
  
  <p>Code:
  urls.py for links related to book</p>
  
  <pre><code>urlpatterns = [
      path('books/', views.BookListView.as_view(), name='books'),
      path('book/&lt;int:pk&gt;', views.BookDetailView.as_view(), name='book-detail'),
      path('mybooks/', views.LoanedBooksByUserListView.as_view(), name='my-borrowed'),
  ]
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>class BookDetailView(LoginRequiredMixin, generic.DetailView):
      model = Book
  
      def get_context_data(self, **kwargs):
          context = super(BookDetailView, self).get_context_data(**kwargs)
          process_data(self.request)
          return context
  
  class LoanedBooksByUserListView(LoginRequiredMixin, generic.ListView):
      """Generic class-based view listing books on loan to current user. """
      model = BookInstance
      template_name = 'catalog/bookinstance_list_borrowed_user.html'
  
      def get_queryset(self):
          return BookInstance.objects.filter(borrower=self.request.user).filter(status__exact='o').order_by('due_back')
  
      def get_context_data(self, **kwargs):
          context = super(LoanedBooksByUserListView, self).get_context_data(**kwargs)
          process_data(self.request)
          return context
  </code></pre>
  
  <p>Template</p>
  
  <pre><code>{% for bookinst in bookinstance_list %}
        &lt;li class="{% if bookinst.is_overdue %}text-danger{% endif %}"&gt;
          &lt;a href="{% url 'book-detail' bookinst.book.pk %}"&gt;{{bookinst.book.title}}&lt;/a&gt; ({{ bookinst.due_back }})
        &lt;/li&gt;
        {% endfor %}
  </code></pre>
  
  <p>Yesterday night, after this post, I turned off DEBUG for security purpose, ie set DEBUG=False for staging env, as well as for local and added host on ALLOWED_HOSTS, local and staging work fine, however prod is throwing 500 error:</p>
  
  <p><em>FYI: staging and prod have same configurations, except host name</em></p>
  
  <blockquote>
    <p>Ref <a href="https://stackoverflow.com/questions/15128135/setting-debug-false-causes-500-error">Setting DEBUG = False causes 500 Error</a></p>
    
    <p>If I rollback to previous committed code, it starts throwing error highighted in this ques</p>
  </blockquote>
  
  <p>And if I verify directly on heroku</p>
  
  <blockquote>
    <p>HP@HP-PC MINGW64 ~/git_projects/prod/django_local_library (master)
    $ heroku run python manage.py runserver --remote heroku-prod</p>
  </blockquote>
  
  <p>It doesn't throw any exception:</p>
  
  <pre><code>Performing system checks...
  System check identified no issues (0 silenced).
  October 09, 2019 - 21:18:54
  Django version 2.2.5, using settings 'locallibrary.settings'
  Starting development server at http://127.0.0.1:8000/
  Quit the server with CONTROL-C.
  </code></pre>
  
  <p>Even the staging logs have no error.</p>
  
  <p>Please help me if someone has ever faced any such issue.</p>