'Reverse for 'Profile' with no arguments not found

I'm trying to add user Profile in my django project. i was trying to access user post into the user Profile but its throws an error like this: Reverse for 'Profile' with no arguments not found. 1 pattern(s) tried: ['profile/(?P[^/]+)/\Z'] and this error is come from my Home template. i want when a user click on profile it will take him/she to the user profile and shows his/she only post he/she did. like social media profile.

the problem is comes from this url in my home template its highlight this urls with this error: NoReverseMatch at /home Reverse for 'Profile' with no arguments not found. 1 pattern(s) tried: ['profile/(?P[^/]+)/\Z']

<li class="nav-item">
   <a class="nav-link active" aria-current="page" href="{% url 'Profile' %}">Profile</a>
</li>

my urls

path('profile/<str:pk>/', views.profile, name='Profile')

my views

def profile(request, pk):
    post = get_object_or_404(Photo, id=pk)
    photo = Photo.objects.get(id=pk)
    user_post = Photo.objects.filter(user=request.user)
    context = {'post':post, 'photo':photo}
    return render(request, 'profile.html')

my model

class Photo(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    category = models.CharField(max_length=30,null=True, blank=False)
    image = CloudinaryField(blank=False, null=False)
    description = models.TextField(null=True)
    date_added = models.DateTimeField(auto_now_add=True)
    phone = models.CharField(max_length=12, null=False, blank=False)
    price = models.CharField(max_length=30,blank=False)
    location = models.CharField(max_length=20, blank=False)

    def __str__(self):
        return str(self.category)

home template

<div class="container">
      <nav class="navbar navbar-expand-lg navbar-light bg-light">
           <div class="container-fluid">
             <a class="navbar-brand" href="#">{{user}}</a>
             <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
               <span class="navbar-toggler-icon"></span>
             </button>
             <div class="collapse navbar-collapse" id="navbarNav">
               <ul class="navbar-nav">
                <li class="nav-item">
                  <a class="nav-link active" aria-current="page" href="{% url 'Profile' %}">Profile</a>
                </li>
                 <li class="nav-item">
                   <a class="nav-link active" aria-current="page" href="{% url 'post_create' %}">Add Product</a>
                  </li>
                  <li class="nav-item">
                    <a class="nav-link active" aria-current="page" href="{% url 'rules' %}">Our Rules</a>
                  </li>
                  <li class="nav-item">
                    <a class="nav-link active" aria-current="page" href="{% url 'feedback' 
                    %}">FeedBack</a>
                  </li>
               </ul>
             </div>
           </div>
        </nav>
 </div>

  <div class="container">
           <div class="row justify-content-center">
                {% for photo in photos reversed %}
                         <div class="col-md-4">  
                             <div class="card my-2">
                               <img class="image-thumbail" src="{{photo.image.url}}" alt="Card image cap">
                            
                               <div class="card-body">
                                    <h2 style="color: yellowgreen; font-family: Arial, Helvetica, sans-serif;">
                                    {{photo.user.username.upper}}
                                    </h2>
                               <br>
                               <h3>{{photo.category}}</h3>
                               
                               <h4>{{photo.price}}</h4>  
                              </div>
                              <a href="{% url 'Photo-view' photo.id %}" class="btn btn-warning btn-sm m-1">Buy Now</a>
                            </div>
                      </div>
                      {% empty %}
                      <h3>No Files...</h3>
                      {% endfor %} 
                     </div> 
      </div>

user profile template

    <div class="container">
    <div class="row justify-content-center">
         {% for photo in photos reversed %}
                  <div class="col-md-4">  
                      <div class="card my-2">
                        <img class="image-thumbail" src="{{photo.image.url}}" alt="Card image cap">
                     
                        <div class="card-body">
                             <h2 style="color: yellowgreen; font-family: Arial, Helvetica, sans-serif;">
                             {{photo.user.username.upper}}
                             </h2>
                        <br>
                        <h3>{{photo.category}}</h3>
                        
                        <h4>{{photo.price}}</h4>  
                       </div>
                       <a href="{% url 'Photo-view' photo.id %}" class="btn btn-warning btn-sm m-1">Buy Now</a>
                     </div>
               </div>
               {% empty %}
               <h3>No Available Post Please Add one</h3>
               {% endfor %} 
              </div> 

Thanks.



Solution 1:[1]

You need pass a identifier in the url.

<li class="nav-item">
   <a class="nav-link active" aria-current="page" href="{% url 'Profile' user_id %}">Profile</a>
</li>

Because in your return reponse, there is not a context

return render(request, 'profile.html',context)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1