NoReverseMatch if "url" template tag not used with app_name

88 views
Skip to first unread message

strang

unread,
Jul 14, 2020, 1:55:03 PM7/14/20
to Django users

I just want to confirm if there has been a change in Django3.x

In Django2.x i could write something like
<a href="{% url 'home' %}">
where 'home' is a url pattern in one of my apps(not the main url file)

But I get NoReverseMatch when I use the same in Django3
I have to use this convention
<a href="{% url 'pages:home' %}">

Which one is correct, for Django3.x?

Exactly musty

unread,
Jul 14, 2020, 2:35:38 PM7/14/20
to Django users
You are using django url, so it should be the same name you gave your url in your URLs.py e.g path('',homeview.as_views, name='home-page')

So if I want to call this url in my template I will use the django url which is {% url 'home-page' %}.

You will have to check your url and see if what you named it matched what you wrote in your django template

strang

unread,
Jul 14, 2020, 4:08:22 PM7/14/20
to Django users
I understand what you are trying to explain.

I have used name=“home” for home view. I’m using urls.py for my app(main URLs.py to route me to my apps urls.py, app urls.py contains path(‘’, HomeView.as_view(), name=‘home’)

But when I try to reference this url in templates ({% url ‘home’%})I get NoReverseMatch error.

However if I use {% url ‘post:home’ %} it works

post is my app name

Franz Ulenaers

unread,
Jul 15, 2020, 2:05:07 PM7/15/20
to Django users
It seems you have specified an app_name in your post/urls.py :

app_name='post'

Have you different name='home' in your apps then you have to use the app_name to make it unique !!


Op dinsdag 14 juli 2020 22:08:22 UTC+2 schreef strang:
Reply all
Reply to author
Forward
0 new messages