Search code examples
pythondjangodjango-templatesdjango-urls

Refer to admin site using {% url 'admin' %} in app django


i wanna Move user to admin panel site in Django using {% url 'admin' %} but the problem is my template in rendering in an app and i dont wanna rewrite url("^admin/",admin.site.urls) in project/site/urls.py

here it is

project / urls.py

urlpatterns = [
url(r"^admin/", admin.site.urls, name="admin"),
url(r"^", include("core.urls")),]

project / site / urls.py

urlpatterns = [
url(r"^$",indexView.as_view() ,name="index" ),
]
accountspattenrns = {
url(r"^accounts/signup/$",signupView.as_view() ,name="signup" ),    
url(r"^accounts/login/$",loginView.as_view() ,name="login" ),    
url(r"^accounts/logout/$",logoutView.as_view() ,name="logout" ),    
url(r"^accounts/profile/$",ProfileView.as_view() ,name="profile" ),    
}
urlpatterns +=accountspattenrns

template.html

<li><a href="{% url 'admin' %}"><i class="fa fa-black-tie fa-2x"></i>
<div>Admin</div></a></li> 

Error :

Error i got


Solution

  • Try reversing the URL using admin namespace

    {% url 'admin:index' %}
    

    Refs: Django docs