Django / Python Error: Could not parse the remainder: ' Server' from 'SQL Server'

Im getting this error when rendering an HTM file on my Django instance. It is thrown in a py-script tag. However, if I drop the following code into a .py file and run/debug it in either Powershell or VSCode, its just fine. I just started learning Python and Django and its neat. It took me a couple of days to get it set up and running, and I like it very much. Anyway

Code:

<py-script>
        print("booyaaaa")
        import pyodbc
        import ctypes 

        connectionString = "DRIVER={{SQL Server}};SERVER=###;DATABASE=###;UID=##;PWD=###"
        conn = pyodbc.connect(connectionString) 
        SQL_QUERY = """
        SELECT TOP 55 * FROM dbo.tbl### ORDER BY ID DESC
        """


        cursor = conn.cursor()
        cursor.execute(SQL_QUERY)


        records = cursor.fetchall()

        recordString = ""

        for r in records:
            recordString += str(r.DonorID) + "\n"

        print(recordString)
    </py-script>

Error:

Environment:


Request Method: GET
Request URL: http://localhost/

Django Version: 5.0.10
Python Version: 3.13.1
Installed Applications:
['whitenoise.runserver_nostatic',
 'myDjangoProj',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Template error:
In template C:\Users\marlon\myDjangoProj\myDjangoProj\templates\index.htm, error at line 18
   Could not parse the remainder: ' Server' from 'SQL Server'
   8 :  <script defer src="https://pyscript.net/alpha/pyscript.js"></script>
   9 : 
   10 :     <title>PyScript Demo</title>
   11 : </head>
   12 : <body>
   13 :     <py-script>
   14 :         print("booyaaaa")
   15 :         import pyodbc
   16 :         import ctypes 
   17 : 
   18 :         connectionString = "DRIVER= {{SQL Server}} ;SERVER=localhost;###"
   19 :         conn = pyodbc.connect(connectionString) 
   20 :         SQL_QUERY = """
   21 :         SELECT TOP 55 * FROM dbo.### ORDER BY ID DESC
   22 :         """
   23 : 
   24 : 
   25 :         cursor = conn.cursor()
   26 :         cursor.execute(SQL_QUERY)
   27 : 
   28 : 


Traceback (most recent call last):
  File "C:\Python313\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python313\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\marlon\myDjangoProj\myDjangoProj\views.py", line 4, in index
    return render(request, 'index.htm')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python313\Lib\site-packages\django\shortcuts.py", line 25, in render
    content = loader.render_to_string(template_name, context, request, using=using)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python313\Lib\site-packages\django\template\loader.py", line 61, in render_to_string
    template = get_template(template_name, using=using)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python313\Lib\site-packages\django\template\loader.py", line 15, in get_template
    return engine.get_template(template_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python313\Lib\site-packages\django\template\backends\django.py", line 33, in get_template
    return Template(self.engine.get_template(template_name), self)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python313\Lib\site-packages\django\template\engine.py", line 177, in get_template
    template, origin = self.find_template(template_name)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python313\Lib\site-packages\django\template\engine.py", line 159, in find_template
    template = loader.get_template(name, skip=skip)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python313\Lib\site-packages\django\template\loaders\cached.py", line 57, in get_template
    template = super().get_template(template_name, skip)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python313\Lib\site-packages\django\template\loaders\base.py", line 28, in get_template
    return Template(
           
  File "C:\Python313\Lib\site-packages\django\template\base.py", line 154, in __init__
    self.nodelist = self.compile_nodelist()
                    ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python313\Lib\site-packages\django\template\base.py", line 196, in compile_nodelist
    return parser.parse()
           ^^^^^^^^^^^^^^
  File "C:\Python313\Lib\site-packages\django\template\base.py", line 481, in parse
    raise self.error(token, e)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python313\Lib\site-packages\django\template\base.py", line 479, in parse
    filter_expression = self.compile_filter(token.contents)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python313\Lib\site-packages\django\template\base.py", line 597, in compile_filter
    return FilterExpression(token, self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python313\Lib\site-packages\django\template\base.py", line 698, in __init__
    raise TemplateSyntaxError(
    ^

Exception Type: TemplateSyntaxError at /
Exception Value: Could not parse the remainder: ' Server' from 'SQL Server'

Any tips or trix would be greatly appreciated!

-Marlon

I googled this error, and all I got was bad format in the py-script tag.

Back to Top