Tuesday, November 26, 2019

Re:

Check your url, you are passing a primary key in the edit_profile function but you are not indicating that in your url.


On Mon, 25 Nov 2019, 05:50 Paras Jain, <parasjain329@gmail.com> wrote:
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.

--
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/CAPCf-y47Zkh-bcQ6cazsfB0%3DhFahxKrc4LkAzv-_a6tfSJnV9Q%40mail.gmail.com.

No comments:

Post a Comment