django _view_() takes 1 positional argument but 2 were given

  • Last Update :
  • Techknowledgy :

As stated in the error message, your view needs to take a second parameter:

def user(request, second_param):
   return render(request, 'home/user_page.html')

If you prefer the previous behaviour, remove the parenthesis from your regex:

r '^users/[a-zA-Z0-9.]+/$'

Suggestion : 2

1 Python Dictionary get() August 7, 2022

If you look at the below example, we have an Employee class, and we have a simple method that takes the name as a parameter and prints the Employee ID as output.

# Employee Class
class Employee:
   # Get Employee method without self parameter
def GetEmployeeID(name):
   print(f "The Employee ID of {name} ", 1234)

# instance of the employee
empObj = Employee()
empObj.GetEmployeeID("Chandler Bing")

Output

Traceback (most recent call last):
File "c:\Personal\IJS\Code\main.py", line 10, in <module>
   empObj.GetEmployeeID("Chandler Bing")
   TypeError: Employee.GetEmployeeID() takes 1 positional argument but 2 were given

As shown below, we can fix the issue by passing the “self” as a parameter explicitly to the GetEmployeeID() method.

# Employee Class
class Employee:
   # Get Employee method with self parameter
def GetEmployeeID(self, name):
   print(f "The Employee ID of {name} ", 1234)

# instance of the employee
empObj = Employee()
empObj.GetEmployeeID("Chandler Bing")

Suggestion : 3

Last updated: Apr 20, 2022

Copied!class Employee():
   #👇️ forgot to specify `self`
arg
def get_name(name):
   return name

emp = Employee()

#⛔️ TypeError: Employee.get_name() takes 1 positional argument but 2 were given
print(emp.get_name('Alice'))
Copied!class Employee():
   #✅ specify self as first arg
def get_name(self, name):
   return name

emp = Employee()

print(emp.get_name('Alice')) #👉️ "Alice"
Copied!class Employee():
   @staticmethod
def get_name(name):
   return name

emp = Employee()

print(emp.get_name('Alice')) #👉️ "Alice"
Copied!#⛔️ TypeError: do_math() takes 1 positional argument but 2 were given
def do_math(a):
   return a * a

result = do_math(5, 10)
Copied!def do_math(a):
   return a * a

result = do_math(5)

print(result) #👉️ 25
Copied!def do_math(a, b):
   return a * b

result = do_math(5, 10)

print(result) #👉️ 50

Suggestion : 4

and this the button in the view file:,I'm trying to create a new file on my pc using an odoo button. this is the function in the models file of the Module:,Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc., Remove @api.model after that will workhttps://www.odoo.com/forum/help-1/question/in-wich-cases-should-we-use-api-model-113720https://www.odoo.com/forum/help-1/question/odoo-11-difference-between-the-api-multi-and-api-model-decorators-137544

I'm trying to create a new file on my pc using an odoo button. this is the function in the models file of the Module:

class AccountMove(models.Model): _inherit = "account.move"
#some fields here @api.model def write_new_file(self): with open('/home/msaeb/newFile.txt', 'w') as new_file: new_file.write("some text here")

and this the button in the view file:

    <record id="account_move_order_inherit" model="ir.ui.view">
       <field name="name">account.move.order.inherit</field>
       <field name="model">account.move</field>
       <field name="inherit_id" ref="account.view_move_form" />
       <field name="arch" type="xml">
          <field name="invoice_date" position="after">
             <field name="expire_date" />
          </field>
          <field name="ref" position="after">           
             <field name="some_field_here" /> <span> <button name="write_new_file" string="creates new text file" type="object" class="btn btn-primary" /> </span>
          </field>     ...     ...

whenever I click the button I got the following error:

خطأ: Odoo Server ErrorTraceback(most recent call last): File "/usr/lib/python3/dist-packages/odoo/http.py", line 619, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception) File "/usr/lib/python3/dist-packages/odoo/http.py", line 309, in _handle_exception raise pycompat.reraise(type(exception), exception, sys.exc_info()[2]) File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 14, in reraise raise value File "/usr/lib/python3/dist-packages/odoo/http.py", line 664, in dispatch result = self._call_function( ** self.params) File "/usr/lib/python3/dist-packages/odoo/http.py", line 345, in _call_function
return checked_call(self.db, * args, ** kwargs) File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 93, in wrapper
return f(dbname, * args, ** kwargs) File "/usr/lib/python3/dist-packages/odoo/http.py", line 338, in checked_call result = self.endpoint( * a, ** kw) File "/usr/lib/python3/dist-packages/odoo/http.py", line 910, in __call__
return self.method( * args, ** kw) File "/usr/lib/python3/dist-packages/odoo/http.py", line 510, in response_wrap response = f( * args, ** kw) File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1324, in call_button action = self._call_kw(model, method, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1312, in _call_kw
return call_kw(request.env[model], method, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/api.py", line 391, in call_kw result = _call_kw_model(method, model, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/api.py", line 364, in _call_kw_model result = method(recs, * args, ** kwargs) TypeError: write_new_file() takes 1 positional argument but 2 were given

 Remove @api.model after that will work
https://www.odoo.com/forum/help-1/question/in-wich-cases-should-we-use-api-model-113720
https://www.odoo.com/forum/help-1/question/odoo-11-difference-between-the-api-multi-and-api-model-decorators-137544

def write_new_file(self): with open('/home/msaeb/newFile.txt', 'w') as new_file: new_file.write("some text her

Suggestion : 5

Django Rest Framework, TypeError: __init__() takes 1 positional argument but 2 were given,django rest api __init__() takes 1 positional argument but 2 were given,create() takes 1 positional argument but 2 were given. Django rest framework,. How to slove it?,TypeError: __init__() takes 1 positional argument but 2 were given django

You didn't call as_view() function in your url

urlpatterns = [
path('quiz/bookmark/create-remove/<slug:slug>/', views.CreateRemoveBookmarkAPI.as_view(),
   name="bookmark-create-remove-api"),
   ]