I want create url when user click pass to profile page -- NoReverseMatch at /home

i want create url when user click pass to profile page

enter image description here

++++ models

class profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    music = models.CharField(max_length=50)
    skils = models.CharField(max_length=50)
    search = models.CharField(max_length=50)
    posts = models.CharField(max_length=50)
    boi = models.TextField()
    img = models.ImageField(upload_to="profile-img")

    def __str__(self):
        #return self.user or 'User'
        return str(self.id)

def create_profile(sender, **kwargs):
    if kwargs['created']:
        user_profile = profile.objects.create(user=kwargs['instance'])

post_save.connect(create_profile, sender=User)

+++ views

def home(request): 
    return render(request, 'main-frond.html')

def profile_edit(request, id):
    pro_edit = profile.objects.get(id=id)
    if request.method == 'POST':
        user_form = User_Form(request.POST, request.FILES, instance=pro_edit)
        if user_form.is_valid():
            user_form.save()
            return redirect('profile_views')
    else:
        user_form = User_Form(instance=pro_edit)
    context = {'user_form' : user_form}
    return render(request, 'profile_edit.html', context)

+++url

    path('home', views.home, name="home"),
    path('profile/<int:id>/edit', views.profile_edit, name="profile_edit")

+++ html

<a href="{% url 'profile_views' %}">profile</a>

django give me problem

Reverse for 'profile_views' with no arguments not found. 1 pattern(s) tried: ['profile/(?P<id>[0-9]+)\\Z']

i want create url when user click pass to profile page

It appears that you are trying to create a URL for a Django application that is not properly configured. The error message "Reverse for 'profile_views' with no arguments not found" suggests that you have not provided the correct arguments in the URL pattern for the 'profile_views' view.

It looks like in the URL pattern, you are expecting an argument 'id' to be passed to the view but it is not being passed. Make sure that you are passing the 'id' argument in the URL when redirecting the user to the profile page.

For example, you can pass the id in the URL like this:

path('profile/<int:id>/', views.profile_views, name='profile_views'),

and then in your views.py

def profile_views(request, id):
    profile = get_object_or_404(Profile, pk=id)
    return render(request, 'profile.html', {'profile': profile})

Then when redirecting the user to the profile page, you can pass the 'id' of the profile like this:

return redirect('profile_views', id=profile.id)

You should also make sure that the profile_views function is defined in views.py and that it is imported in your urls.py file.

Back to Top