<li class="nav-item">
<a class="nav-link" href="{% url 'profile' user %}">
<img src= {% static 'network/images/profile.svg' %} alt="Profile" class="left-sidebar-menu-icon">
Profile
</a>
<!-- {{ user.id }} THIS IS TO SEE THE ID SHOWING-->
</li>
When I use the above template with this “{% url ‘profile’ user %}”, my index page(http://127.0.0.1:8000/) gives me this error - Reverse for ‘profile’ with arguments ‘(<SimpleLazyObject: <User: Noble>>,)’ not found. 1 pattern(s) tried: [‘profile/(?P<user_id>[0-9]+)\Z’]
However, my profile page (http://127.0.0.1:8000/profile/4) shows without any error.
So with the above solution, I can access the profile page but not the index page
Profile template section 2
<li class="nav-item">
<a class="nav-link" href="{% url 'profile' user.id %}">
<img src= {% static 'network/images/profile.svg' %} alt="Profile" class="left-sidebar-menu-icon">
Profile
</a>
<!-- {{ user.id }} THIS IS TO SEE THE ID SHOWING AND IT SHOWS 4-->
</li>
When I use the above template with this “{% url ‘profile’ user.id %}”, my index page(http://127.0.0.1:8000/) shows without any error.
However, my profile page (http://127.0.0.1:8000/profile/4) gives me this error - Reverse for ‘profile’ with arguments ‘(’‘,)’ not found. 1 pattern(s) tried: [‘profile/(?P<user_id>[0-9]+)\Z’] - even though the {{ user.id }} on the index page shows the id - 4
So with the above solution, I can access the index page but not the profile page
It appears that both index.html and profile.html may extend layout.html, is that correct?
If so, since layout.html has this:
then it (layout.html) is expecting that user is an object and not an id.
That means you then need to change your profile view.
In that view you have:
But, since layout.html is expecting the User object and not just the id field for that User object, it should be user = profile_user.
Now, it gets a little more complex than this, because you likely have django.contrib.auth.context_processors.auth in the TEMPLATES setting. This context processor injects the current user into the context under the name user. Your redefinition of user in the context could interfere with other default behavior.
Therefore, what I also recommend is that you don’t use the name user in your view to pass a User object that isn’t the requesting user to the template.
I’d suggest you actually remove that line completely and the "user": user line from the context.
Then, in your template, when you need to create the url reference to that profile, you use {% url 'profile' profile_user.id %}
But you want to be sure you’re clear in your template when you want to reference the current user (user) and when you want to refer to a different user (profile_user)
You don’t need to explicitly include user in the context if you have django.contrib.auth.context_processors.auth in your context_processors in the TEMPLATES section of your settings.
That would not cause user.id to show “None”. In fact, it wouldn’t show anything at all.
But still getting - Reverse for ‘profile’ with arguments ‘(’‘,)’ not found. 1 pattern(s) tried: [‘profile/(?P<user_id>[0-9]+)\Z’] at the url path - http://127.0.0.1:8000/
I also tried altering this - but i get same error <a class="nav-link" href="{% url 'profile' profile_user %}">