After reading I have understood the following, I can do the query as follows, and using a specific connection (sql)
def NoConformidad(request):
with connections['nav_db'].cursor() as cursor:
cursor.execute("SELECT Name FROM Customer")
row = cursor.fetchone()
return row
Possibly? I don’t recognize that port number (7048).
The error is being thrown in the psycopg2 module, so it’s one of the databases you’ve got defined as a PostgreSQL server. The full traceback would help identify which line caused the error.
Note: Please don’t paste an image of a traceback. Copy/paste the traceback from the console log.
I can’t tell you what you should put without knowing what database you’re trying to connect to, what server it’s running on, and what type of database it is.
Side note, in the future, you will want to refer to your database as “SQL Server” or “MS SQL Server”, not just as “sql”. The acronym “sql” is a generic term that applies to a number of different things.
Ok, now I think that it is already correctly connected to SQL Server but I don’t know how to check it since the query tells me the following.
Internal Server Error: /noConformidad/
Traceback (most recent call last):
File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\apenaranda\Desktop\Python_Intranet\env\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\apenaranda\Desktop\Python_Intranet\reclamaciones\views.py", line 151, in NoConformidad
cursor.execute("SELECT Golmar$Customer.Name FROM Golmar$Customer WHERE Golmar$Customer.Name = 'DISTRIBUIDORES-7' ", [self.Name])
^^^^^^^^^
AttributeError: 'WSGIRequest' object has no attribute 'Name'
Query in views.py
def NoConformidad(self):
with connections['nav_db'].cursor() as cursor:
cursor.execute("SELECT Name FROM Golmar$Customer WHERE Name = DISTRIBUIDORES-7", [self.Name])
row = cursor.fetchone()
return row
Well I already managed to get the information with
with connections['nav_db'].cursor() as cursor:
cursor.execute("SELECT * FROM Golmar$Customer WHERE Name = 'DISTRIBUIDORES-7';") # Here
for row in cursor.fetchall(): # Here
print(row)
print(cursor.fetchall()) # []
return HttpResponse("NoConformidad")
What if I want to show it on the page and not on the console?