0

Could anybody please tell me how to realize a navigation bar containing among others an item leading to admin page? It should like this

                                                 Home | Faculty | Student | Admin 

In the following code, it works for all items in the bar, except the 'admin' one:

<ul class="nav navbar-nav navbar-right">
    <li><a href="{% url 'home' %}">Home</a></li>
    <li><a href="{% url 'faculty' %}">Faculty</a></li>
    <li><a href="{% url 'student' %}">Student</a></li>
    <li><a href="{% url 'admin' %}">Admin</a></li>
</ul>

In the urls file admin is described as follows:

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

I would also appreciate if anyone enlighten me on how to make the 'admin' item visible only for superuser. Thank you very much!

Vvan_G
  • 205
  • 1
  • 4
  • 13
  • 1
    and for the second question see [this answer](https://stackoverflow.com/a/10065699/1418794) – doru Jun 19 '17 at 20:22
  • @doru Thank you very much, I should better take a course on how to use a search engine instead of django coding. – Vvan_G Jun 19 '17 at 20:46

1 Answers1

1

Try this

<ul class="nav navbar-nav navbar-right">
    <li><a href="{% url 'home' %}">Home</a></li>
    <li><a href="{% url 'faculty' %}">Faculty</a></li>
    <li><a href="{% url 'student' %}">Student</a></li>

        {% if request.user.is_superuser %}
    <li><a href="{% url 'admin' %}">Admin</a></li>
    {% endif %}

</ul>

Don't forget to check permissions in the view of url admin too.

Javier Campos
  • 365
  • 3
  • 13