nikolas nikolas - 2 months ago 107
Python Question

NoReverseMatch in Django 1.10

Here is my url.py

from django.conf.urls import url
from django.contrib import admin
from app import views, auth
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', views.index, name = 'index'),
url(r'^login/', auth.login, name = 'login'),
url(r'^logout/', auth.logout, name = 'logout'),
]


When I'm using in template
<li><a href="{% url 'admin' %}">Administration</a></li>
get error

NoReverseMatch at /
Reverse for 'admin' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []


So can any one tell me how to solve this? Thank you very much.

Answer

1 . Make a url.py in app folder and use

urlpatterns = [
    url(r'^admin/', admin.site.urls),
]

and in template use

<a href="{% url 'admin:index' %}">Admin</a>

or

  1. Use <a href="/admin">Admin</a> and left url.py as it is(make no changes)