title: Django bug report, different foreign key as URL parameter will cause detailed view not executing
body: <p><strong>Edit3:</strong>
  <strong>the culprit is re_path, not foreign key</strong></p>
  <p><strong>Original:</strong></p>
  <p>This bug is so subtle I couldn't really find a niche way to describe it, For example I have two apps, News and Blogs</p>
  <p>In blogs.py model I have something like this:</p>
  <pre><code>class BlogType(models.Model):
      blog_type = CharField(max_length=20)
      def __str__(self):
          return self.blog_type
  
  class Blogs(models.Model):
      title = models.CharField(max_length=20)
      blog_author = models.ForeignKey(User, on_delete=models.CASCADE)
      blog_type = models.ForeignKey(BlogType, on_delete=models.DO_NOTHING)
  </code></pre>
  <p>here a blog_type is a foreignkey defined inside the same models.py</p>
  <p>In blogs url.py</p>
  <pre><code>from django.urls import path, re_path
  from . import views
  from .views import blogspage
  
  urlpatterns = [
      path('', views.blogs, name='blogs'),
      re_path(r'(?P&lt;blog_type&gt;[\w-]+)/(?P&lt;pk&gt;[0-9]+)$', blogspage.as_view(), name='blogspage'),
  ]
  </code></pre>
  <p>Here using the forignkey as a url parameter</p>
  <p>And in blogs views.py</p>
  <pre><code>class blogspage(DetailView):
      model=Blogs
      template_name='blogs/blogspage.html'
      def get_context_data(self, **kwargs):
          context = super().get_context_data(**kwargs)
          print('Print the object if this is executed', self.get_object())
  </code></pre>
  <p>In Django template you would pass something like:</p>
  <pre><code>&lt;div&gt;&lt;a href=&quot;{% url 'blogspage' b.blog_type b.id %}&quot;&gt;{{b.title}}&lt;/a&gt;&lt;/div&gt;
  </code></pre>
  <p>Now the news model.py you have:</p>
  <pre><code>class NewsType(models.Model):
      news_type = CharField(max_length=20)
      def __str__(self):
          return self.news_type
  
  class News(models.Model):
      title = models.CharField(max_length=20)
      news_author = models.ForeignKey(User, on_delete=models.CASCADE)
      news_type = models.ForeignKey(NewsType, on_delete=models.DO_NOTHING)
  </code></pre>
  <p>The news views, news urls, news templates, are the exactly the same as blog except the name and template name, basically replacing every single &quot;blogs&quot; to &quot;news&quot;</p>
  <p>Then here is where the bug would occur, Only one detailed view will ever execute, for example when someone clicks &quot;<code>{%url &quot;blogspage&quot; blog.blog_type blog.id%}</code>&quot; It will go to url blog/blog_type/pk but the content will be news, However, If <code>&lt;foreignkey&gt; blog_type</code> is removed from url parameter, Only then the detailed view of blog will execute and the correct blog content will be rendered.</p>
  <p>news url.py:</p>
  <pre><code>urlpatterns = [
      path('', views.news, name='news'),
      re_path(r'(?P&lt;news_type&gt;[\w-]+)/(?P&lt;pk&gt;[0-9]+)$', newspage.as_view(), name='newspage'),
  ]
  </code></pre>
  <p>root url.py</p>
  <pre><code>urlpatterns = [
      path('admin/', admin.site.urls),
      path('', include('news.urls')),
      path('blogs/',include('blogs.urls')),
  ] # path('news/', include('news.urls')), will not conflit
  # switch the position between blogs.urls and news.urls also no conflit
  </code></pre>
  <p><strong>Edit</strong>: <a href="http://www.example.com/blogs/blog_type/1" rel="nofollow noreferrer">www.example.com/blogs/blog_type/1</a> and <a href="http://www.example.com/news/news_type/1" rel="nofollow noreferrer">www.example.com/news/news_type/1</a> will not conflit but <a href="http://www.example.com/blogs/blog_type/1" rel="nofollow noreferrer">www.example.com/blogs/blog_type/1</a> and <a href="http://www.example.com/news_type/1" rel="nofollow noreferrer">www.example.com/news_type/1</a> will</p>
  <p><strong>Edit2</strong>: Because &quot;&quot; and &quot;/blogs&quot; bugged I automatically assume &quot;/blogs&quot; and &quot;/news&quot; will also bug, But the bug only exist between &quot;&quot; and &quot;/blogs&quot;</p>