How to access from the list template to the detail template in Django 2?

106 Views Asked by At

I'm trying to access from the list template, to detail template

Exmaple:

article: urls

article_patterns = [
  path('', HomePageView.as_view(), name='home')
  path('articles/', ArticleListView.as_view(), name="articles"),
  path('articles/<int:pk>/', ArticleDetailView.as_view(), name="article"),
]

main urls

urlpatterns = [
  path('', include(article_patterns)),
  path('admin/', admin.site.urls),
]

In article_list.html

<a href="{% url 'articles:article' article.id %}"> Detail {{articles.title}}</a>

But I have this error: articles is not a registered namespace

Any ideas or suggestions?

1

There are 1 best solutions below

0
On BEST ANSWER

You can do what floydya says and ignore the namespace. But if you want to include it you should add a namespace argument to the include function in your main.py.

path('', include(article_patterns, namespace="articles"))

Edit:

If you want to take this approach and use a namespace argument you need to follow the advice given in rawken's answer. That is, set up a urls.py file in your articles app (if there is one) and then include the urls module, not just a list of views. See the source code for the include function if you want to see all of the options.