Reverso de ‘news_detail’ con argumentos ‘(‘ ‘,)’ no encontrados. 1 patrón (s) intentado: +) $’]

Este problema solo ocurre en el entorno de producción, en mi entorno de desarrollo local funciona bien.

Template error: In template /home/william/kjmg/templates/base.html, error at line 0 Reverse for 'news_detail' with arguments '('',)' not found. 1 pattern(s) tried: ['news\\-(?P[0-9]+)$'] 1 :  2 :  3 : {% load staticfiles %} 4 :  5 :  6 :  7 :  8 : {# 导航栏图标显示 #} 9 :  10 : <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}" Traceback: File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner 35. response = get_response(request) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response 128. response = self.process_exception_by_middleware(e, request) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response 126. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/views/generic/base.py" in view 69. return self.dispatch(request, *args, **kwargs) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/views/generic/base.py" in dispatch 89. return handler(request, *args, **kwargs) File "/home/william/kjmg/apps/news/views.py" in get 68. 'opinion_news': opinion_news, File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/shortcuts.py" in render 36. content = loader.render_to_string(template_name, context, request, using=using) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/template/loader.py" in render_to_string 62. return template.render(context, request) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/template/backends/django.py" in render 61. return self.template.render(context) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/template/base.py" in render 175. return self._render(context) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/template/base.py" in _render 167. return self.nodelist.render(context) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/template/base.py" in render 943. bit = node.render_annotated(context) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/template/base.py" in render_annotated 910. return self.render(context) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/template/loader_tags.py" in render 155. return compiled_parent._render(context) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/template/base.py" in _render 167. return self.nodelist.render(context) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/template/base.py" in render 943. bit = node.render_annotated(context) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/template/base.py" in render_annotated 910. return self.render(context) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/template/loader_tags.py" in render 67. result = block.nodelist.render(context) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/template/base.py" in render 943. bit = node.render_annotated(context) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/template/base.py" in render_annotated 910. return self.render(context) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/template/defaulttags.py" in render 447. url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/urls/base.py" in reverse 88. return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)) File "/home/william/kjmg/kjmgenv/lib/python3.5/site-packages/django/urls/resolvers.py" in _reverse_with_prefix 632. raise NoReverseMatch(msg) Exception Type: NoReverseMatch at / Exception Value: Reverse for 'news_detail' with arguments '('',)' not found. 1 pattern(s) tried: ['news\\-(?P[0-9]+)$'] 

El entorno de producción es digitalocean ubuntu 16.04.La versión de desarrollo de python es 3.6, la versión de producción de python es 3.5.

Aquí está mi urls.py:

 urlpatterns = [ path('', NewsView.as_view(), name='index'), path('news', include(('news.urls', 'news'), namespace="news")), ] 

Aquí hay noticias / urls.py:

 from .views import newsDetailView urlpatterns = [ path('-', views.newsDetailView, name="news_detail"), path('tag_lists-', views.tagNewsList, name="tag_news_list"), path('category_lists-', views.categoryNewsList, name="category_news_list"), ] 

Aquí hay noticias / views.py

  class NewsView(View): """首页新闻列表""" def get(self, request): all_news = News.objects.all().filter(select_news__isnull=True).exclude(category__name="opinion").order_by('-pk') return render(request, 'index.html', { 'all_news': news, }) def newsDetailView(request, news_pk): news = get_object_or_404(News, id=news_pk) News.objects.filter(id=news_pk).update(pv=F('pv') + 1) relative_news = News.objects.filter(tag__id__in=news.tag.all()).exclude(id=news_pk)[:6] return render(request, "news_detail.html", { 'news': news, 'relative_news': relative_news }) 

Aquí está el index.html:

  {% for news in all_news.object_list %} 
  • Generic placeholder image
  • Para ayudar a las personas que pueden enfrentar el mismo problema. Necesito responder esta pregunta.

    Probé en mi máquina local que funciona bien. Pero si cambio una nueva base de datos ocurre el mismo problema.

    Así que me doy cuenta de que, este problema es causado por la base de datos vacía! Solo ingresa algo en tu base de datos funcionará!