NoReverseMatch at /projects/ Reverse for 'user-profile' with arguments '('',)' not found.

Hi I am just getting started with Django but for some reason I am getting this error over and over again. It’s probably something related to the owner in projects.html, because if i click on the link I get the error message from the title. Thanks for your help.


class Project(models.Model):
owner = models.ForeignKey(Profile, null=True, blank=True, on_delete=models.SET_NULL)
title = models.CharField(max_length=200)


class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, null=True, blank=True)
name = models.CharField(max_length=200, blank=True, null=True)

def userProfile(request, pk):
profile = Profile.objects.get(id=pk)
context = {‘profile’:profile}
return render(request, ‘users/user-profile.html’, context)


{% for project in projects %}
href="{% url ‘user-profile’ %}"

{% endfor %}
path(‘profile/str:pk/’, views.userProfile, name=“user-profile”),

Side note: When posting blocks of code (or templates) here, surround the block between lines of three backtick - ` characters. That means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted, and prevents it from trying to iterpret or filter lines. (The backtick lines must be lines on their own, before and after each block.)

You show the projects.html template, but you don’t show the view that is supposed to render that template. It’s that view we need to see, not the userProfile view.

Generally speaking, that error comes from the url tag needing a parameter not being supplied. For some reason, at that point in the template, doesn’t return a value. Usually, what I see around here for that situation is that the context isn’t created correctly.

Okay thanks for your reply. Thats my projects view

def projects(request):
    projects = Project.objects.all()
    context = {'projects':projects}
    return render(request, 'projects/projects.html', context)

Ok, three questions then:

Have you verified that there’s a non-blank name for every owner in project?

What are you expecting the “user-profile” url to look like when it’s rendered?

What should you be passing to the url tag as a parameter?

  1. That´s a part of the Project model. So yeah blank=True
class Project(models.Model):
    owner = models.ForeignKey(Profile, null=True, blank=True, on_delete=models.SET_NULL)
  1. The template should render out some basic informations about the user

  2. I don´t know if I got that right but after the url ‘user-profile’ I typed the in to navigate to the specific site of the user who created this project

Ok, let’s try this from a slightly different direction.

You have:

Which then directs you to:

So, in the url - that first line. What does the <str:pk> part mean, and how does it relate to that view?

Here is the id part, which relates to pk in

    id = models.UUIDField(default=uuid.uuid4, unique=True, primary_key=True, editable=False)

id = pk
So the url should look like this: user-profile/ UUID part

Ok, so that means in your creation of your URL in your template, you need to pass the UUID part in your url tag.