Search code examples
djangoview

Django funcion views, creating a company with user associated


So, i have this problem when im trying to create my "company", when i didnt have user authentication the view worked just fine. Now i've added django allauth, and this screen appears to me: enter image description here

So i will leave here my model and my view to create the company Im just a begginner so sry for my bad explanation

enter image description here

enter image description here

The URLS : https://prnt.sc/K-lKvmfuQtvR


Solution

  • It looks like the problem is with the way your url is setup. Do you have a screenshot of the urls.py as well so we can see how you setup your url mapping. (OP added this screenshot: prnt.sc/K-lKvmfuQtvR)

    Your companies/<pk>/ endpoint is catching your "create_company" value and storing it as a variable. Try moving your companies/create_company path above your companies/<pk>/ like so

    path('companies/', listing_companies),
    path('companies/create_company/', company_create),
    path('companies/<pk>', retrieve_companies),
    path('companies/<pk>/update/', company_update),
    path('companies/<pk>/delete/', company_delete),
    
    

    Alternatively rename companies/create_company/ to create_company/ like so

    path('companies/', listing_companies),
    path('companies/<pk>', retrieve_companies),
    path('create_company/', company_create),
    path('companies/<pk>/update/', company_update),
    path('companies/<pk>/delete/', company_delete),
    

    The end goal in either case is simply to make sure your paths are not capturing your "create_company" and storing it as that variable that it is passing along to your path's method.