Sunday, November 24, 2019

its showing error like this:

TypeError at /edit_profile/

edit_profile() missing 1 required positional argument: 'pk'
views.py:
def edit_profile(request, pk):
    post = get_object_or_404(User, pk=pk)
    if request.method == "POST":
        form = EditProfileForm(request.POST, instance=post)
        if form.is_valid():
            post = form.save(commit=False)
            post.save()
            return redirect('company/detail.html', pk=post.pk)
    else:
        return render(request,'company/edit_profile.html')


def detail(request,pk):
    details = get_object_or_404(User, pk=pk)         #it will create object
    return render(request, 'company/detail.html',{'details':details})


urls.py:

from django.urls import path
from django.conf.urls import  url
#from .views import HomePageView
from .import views

urlpatterns=[
    path('', views.home, name='company-home'),
    path('register/', views.register, name='company-register'),
    path('detail/<int:pk>', views.detail, name='company-detail'),
    path('login/', views.login, name='company-login'),
    path('add/', views.add, name='company-add'),
    path('edit_profile/', views.edit_profile, name='company-edit'),


]


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMtmBS9%2B50Ms6HepVL692bjMP8oO9qYY49xWJDHyFUP8AJJgiQ%40mail.gmail.com.

No comments:

Post a Comment