# Access Object in Navbar is Failed

**URL:** <https://forum.djangoproject.com/t/access-object-in-navbar-is-failed/13613>\
**Category:** Forms & APIs\
**Created:** [May 9, 2022, 6:53pm UTC](https://forum.djangoproject.com/t/access-object-in-navbar-is-failed/13613 "2022-05-09T18:53:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AhmdMWddh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ahmdmwddh/32/21707_2.png) [@AhmdMWddh](https://forum.djangoproject.com/u/AhmdMWddh)\
**Post date:** [May 9, 2022, 6:53pm UTC](https://forum.djangoproject.com/t/access-object-in-navbar-is-failed/13613/1 "2022-05-09T18:53:22Z")

</div>

i have a navbar with link sales office under contact us but i cant give it url to open this page with its view, i tried also to create a Context\_processors,py but also failed.  
I Hope Any One Has Any Clue To Ding After.

Model:

```auto
class Branch(models.Model):
    name = models.CharField(verbose_name='Name', max_length=255)
    region = models.CharField(verbose_name='Region', max_length=255)
    country = models.CharField(verbose_name='Country', max_length=255)
    state = models.CharField(verbose_name='State', max_length=255)
    city = models.CharField(verbose_name='City', max_length=255)
    street = models.CharField(verbose_name='Street', max_length=255)
    slug = models.SlugField(verbose_name='Slug', unique=True)
    email = models.EmailField(verbose_name='EMail', unique=True)
    website = models.URLField(verbose_name='Website')
    mobile = models.CharField(verbose_name='Mobile', max_length=255)
    phone = models.CharField(verbose_name='Phone', max_length=255)
    location = models.CharField(verbose_name='Location', max_length=255)
    image = models.ImageField(verbose_name='Image', upload_to=upload_branch_image, default=default_image)

    class Meta:
        verbose_name_plural = 'Branches'
        ordering = ['region', 'country', 'state', 'city']

    def get_absolute_url(self):
        return reverse('pages:eg_sales_office', args={'slug': str(self.slug)})

    def __str__ (self):
        return f'{self.name}'

```

Views

```auto
def eg_sales_office(request, slug):
    branch = get_object_or_404(Branch, slug=slug)
    page = f'{branch} Sales Office'
    context = {'page': page, 'branch': branch}
    return render(request, 'pages/eg-sales-office.html', context)

```

URLs

```auto
from django.urls import path

from pages import views

app_name = 'pages'

urlpatterns = [
    path('', views.index, name='index'),
    path('development-milestone', views.development_milestone, name='development_milestone'),
    path('distributors', views.distributors, name='distributors'),
    path('faqs', views.faqs, name='faqs'),
    path('history', views.history, name='history'),
    path('international-offices', views.international_offices, name='international_offices'),
    path('our-stores', views.our_stores, name='our_stores'),
    path('projects', views.projects, name='projects'),
    path('room-concepts', views.room_concepts, name='room_concepts'),
    path('safety-cetificates', views.safety_cetificates, name='safety_cetificates'),
    path('size-guide', views.size_guide, name='size_guide'),
    path('terms-conditions', views.terms_conditions, name='terms_conditions'),
    path('timeline', views.timeline, name='timeline'),
    path('vision-mission', views.vision_mission, name='vision_mission'),
    path('why-egypt', views.why_egypt, name='why_egypt'),
    path('world-wide', views.world_wide, name='world_wide'),
    path('eg-sales-office/<slug:slug>', views.eg_sales_office, name='eg_sales_office'),
]

```

HTML  
I Tried Both of These Methods For HTML  
1-

```auto
<div class="menu">
      <a class="item" href="{{ branch.get_absolute_url }}">Egypt Sales Office</a>
</div>

```

2-

```auto
<div class="menu">
      <a class="item" href="{% url 'pages:eg_sales_office' slug %}">Egypt Sales Office</a>
</div>

```

3-

```auto
<div class="menu">
      <a class="item" href="{% url 'pages:eg_sales_office' branch.slug %}">Egypt Sales Office</a>
</div>

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 9, 2022, 8:46pm UTC](https://forum.djangoproject.com/t/access-object-in-navbar-is-failed/13613/2 "2022-05-09T20:46:03Z")

</div>

So what is happening with each of these three attempts?

Examine the html that has been rendered in the browser, and show what was generated in the `href` attribute for each of those three different versions.

If you’re getting an error message, please post that.

---

<div class="post-metadata">

**Author:** ![AhmdMWddh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ahmdmwddh/32/21707_2.png) [@AhmdMWddh](https://forum.djangoproject.com/u/AhmdMWddh)\
**Post date:** [May 9, 2022, 9:25pm UTC](https://forum.djangoproject.com/t/access-object-in-navbar-is-failed/13613/3 "2022-05-09T21:25:43Z")

</div>

I Tried Both of These Methods For HTML and Updated With Error Messages.  
1-

```auto
<div class="menu">
      <a class="item" href="{{ branch.get_absolute_url }}">Egypt Sales Office</a>
</div>

```

> Nothing Happens to the link, like it has never got any link. just any page i am on right now.

2-

```auto
<div class="menu">
      <a class="item" href="{% url 'pages:eg_sales_office' slug %}">Egypt Sales Office</a>
</div>

```

and  
3-

```auto
<div class="menu">
      <a class="item" href="{% url 'pages:eg_sales_office' branch.slug %}">Egypt Sales Office</a>
</div>

```

Same Error For 2 and 3

> NoReverseMatch at /pages/
> 
> Reverse for ‘eg\_sales\_office’ with arguments ‘(’‘,)’ not found. 1 pattern(s) tried: [‘pages/eg\-sales\-office/(?P[-a-zA-Z0-9\_]+)\Z’]

Note:  
i find this line in bold with 2 and 3 i don’t know if it has any clue.

`amw/pages/views.py` , line 7, in index`

```auto
def index(request):
       context = {}
       return render(request, 'pages/index.html', context)

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 9, 2022, 9:42pm UTC](https://forum.djangoproject.com/t/access-object-in-navbar-is-failed/13613/4 "2022-05-09T21:42:10Z")

</div>

> [@AhmdMWddh](#):
>
> `amw/pages/views.py` , line 7, in index`

Yes. Very important.

> [@AhmdMWddh](#):
>
> ```auto
> def index(request):
> context = {}
> return render(request, 'pages/index.html', context)
> 
> ```

You’re passing an empty context to the template. None of your template variables are going to have any values.

---

<div class="post-metadata">

**Author:** ![AhmdMWddh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ahmdmwddh/32/21707_2.png) [@AhmdMWddh](https://forum.djangoproject.com/u/AhmdMWddh)\
**Post date:** [May 9, 2022, 9:48pm UTC](https://forum.djangoproject.com/t/access-object-in-navbar-is-failed/13613/5 "2022-05-09T21:48:27Z")

</div>

okay,  
i guess its bad to create Home Page with argument,  
can i do it with Context\_Processors, i already used it with Categories, i will try it and provide if any errors.

thanks alot Kan. be safe

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 9, 2022, 9:51pm UTC](https://forum.djangoproject.com/t/access-object-in-navbar-is-failed/13613/6 "2022-05-09T21:51:14Z")

</div>

> [@AhmdMWddh](#):
>
> i guess its bad to create Home Page with argument,

No. I’m not sure I follow what leads you to that conclusion.

It’s a common pattern to have a home page showing a list of items, each being a link to a more detailed page.

---

<div class="post-metadata">

**Author:** ![AhmdMWddh](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ahmdmwddh/32/21707_2.png) [@AhmdMWddh](https://forum.djangoproject.com/u/AhmdMWddh)\
**Post date:** [May 9, 2022, 10:08pm UTC](https://forum.djangoproject.com/t/access-object-in-navbar-is-failed/13613/7 "2022-05-09T22:08:24Z")

</div>

i guess Home page view will load alot of data. but i will follow you for this .
