creating admin restricted urls
<p>so in my urls.py (outside django  default admin section ) i want to restrict some urls only to admin so if i have this for logged users </p>

<pre><code>  from django.contrib.auth.decorators import login_required

    urlpatterns = [
        url(r'^a1$',login_required( views.admin_area1 ), name='a1'),
        url(r'^a2$', login_required(views.admin_area2) , name='a2'),
        url(r'^a3', login_required(views.admin_area3) , name='a3'),
    ]
</code></pre>

<p>is there enyway torestrict these links to logged admins not just any logged user ? 
there is  but <a href="http://stackoverflow.com/a/12003808/590589">according to this</a> i can use <code>user_passes_test</code> but i have to use it in view </p>

<p>You can use the decorator returned by <code>user_passes_test(lambda u: u.is_superuser)</code> in the same way that you use <code>login_required</code>:</p>

<pre><code>urlpatterns = [
    url(r'^a1$', user_passes_test(lambda u: u.is_superuser)(views.admin_area1), name='a1'),
]
</code></pre>

<p>If you want to restrict access to admins, then it might be more accurate to use the <a href="https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#the-staff-member-required-decorator" rel="nofollow"><code>staff_member_required</code></a> decorator (which checks the <a href="https://docs.djangoproject.com/en/1.10/ref/contrib/auth/#django.contrib.auth.models.User.is_staff" rel="nofollow"><code>is_staff</code></a> flag) instead of checking the <a href="https://docs.djangoproject.com/en/1.10/ref/contrib/auth/#django.contrib.auth.models.User.is_superuser" rel="nofollow"><code>is_superuser</code></a> flag.</p>

<pre><code>from django.contrib.admin.views.decorators import staff_member_required

urlpatterns = [
    url(r'^a1$', staff_member_required(views.admin_area1), name='a1'),
    ...
]
</code></pre>

python django django-1.9