We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Django autoload_handle broken
#### ALL software version info
Panel =  0.13.0a25
Bokeh  = 2.4.2
Django = 2.2.14

When loading a Panel app embedded in Django, the `AutoloadJsConsumer` call just hangs. After stepping through the code it 
appears there is an error, which causes it to enter an eternal loop:

```python
> /Users/rditlsc9/miniconda/envs/tethys-vtime/lib/python3.7/site-packages/panel/io/django.py(37)autoload_handle()
-> js = autoload_js_script(resources, session.token, element_id, app_path, absolute_url)

TypeError: autoload_js_script() missing 1 required positional argument: 'absolute_url'
```

It appears that #2919 changed the signature of `autoload_js_script`, but the call to it in `panel/io/django.py:autoload_handle` wasn't updated accordingly.


As a side note - is there a better way to get this type of error to log? I wasn't able to see any indication of an error until I stepped through the code in a debugger.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `panel/io/django.py`
Content:
```
1 from urllib.parse import urlparse
2 
3 from bokeh.server.django.consumers import DocConsumer, AutoloadJsConsumer
4 
5 from .resources import Resources
6 from .server import (
7     autoload_js_script, server_html_page_for_session
8 )
9 
10 async def doc_handle(self, body):
11     session = await self._get_session()
12     resources = Resources.from_bokeh(self.application.resources())
13     page = server_html_page_for_session(
14         session, resources=resources, title=session.document.title,
15         template=session.document.template,
16         template_variables=session.document.template_variables
17     )
18     await self.send_response(200, page.encode(), headers=[(b"Content-Type", b"text/html")])
19 
20 
21 async def autoload_handle(self, body):
22     session = await self._get_session()
23 
24     element_id = self.get_argument("bokeh-autoload-element", default=None)
25     if not element_id:
26         raise RuntimeError("No bokeh-autoload-element query parameter")
27 
28     app_path = self.get_argument("bokeh-app-path", default="/")
29     absolute_url = self.get_argument("bokeh-absolute-url", default=None)
30 
31     if absolute_url:
32         server_url = '{uri.scheme}://{uri.netloc}/'.format(uri=urlparse(absolute_url))
33     else:
34         server_url = None
35 
36     resources = self.resources(server_url)
37     js = autoload_js_script(resources, session.token, element_id, app_path, absolute_url)
38 
39     headers = [
40         (b"Access-Control-Allow-Headers", b"*"),
41         (b"Access-Control-Allow-Methods", b"PUT, GET, OPTIONS"),
42         (b"Access-Control-Allow-Origin", b"*"),
43         (b"Content-Type", b"application/javascript")
44     ]
45     await self.send_response(200, js.encode(), headers=headers)
46 
47 
48 DocConsumer.handle = doc_handle
49 AutoloadJsConsumer.handle = autoload_handle
50
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/panel/io/django.py b/panel/io/django.py
--- a/panel/io/django.py
+++ b/panel/io/django.py
@@ -34,7 +34,7 @@
         server_url = None
 
     resources = self.resources(server_url)
-    js = autoload_js_script(resources, session.token, element_id, app_path, absolute_url)
+    js = autoload_js_script(session.document, resources, session.token, element_id, app_path, absolute_url)
 
     headers = [
         (b"Access-Control-Allow-Headers", b"*"),

{"golden_diff": "diff --git a/panel/io/django.py b/panel/io/django.py\n--- a/panel/io/django.py\n+++ b/panel/io/django.py\n@@ -34,7 +34,7 @@\n         server_url = None\n \n     resources = self.resources(server_url)\n-    js = autoload_js_script(resources, session.token, element_id, app_path, absolute_url)\n+    js = autoload_js_script(session.document, resources, session.token, element_id, app_path, absolute_url)\n \n     headers = [\n         (b\"Access-Control-Allow-Headers\", b\"*\"),\n", "issue": "Django autoload_handle broken\n#### ALL software version info\r\nPanel =  0.13.0a25\r\nBokeh  = 2.4.2\r\nDjango = 2.2.14\r\n\r\nWhen loading a Panel app embedded in Django, the `AutoloadJsConsumer` call just hangs. After stepping through the code it \r\nappears there is an error, which causes it to enter an eternal loop:\r\n\r\n```python\r\n> /Users/rditlsc9/miniconda/envs/tethys-vtime/lib/python3.7/site-packages/panel/io/django.py(37)autoload_handle()\r\n-> js = autoload_js_script(resources, session.token, element_id, app_path, absolute_url)\r\n\r\nTypeError: autoload_js_script() missing 1 required positional argument: 'absolute_url'\r\n```\r\n\r\nIt appears that #2919 changed the signature of `autoload_js_script`, but the call to it in `panel/io/django.py:autoload_handle` wasn't updated accordingly.\r\n\r\n\r\nAs a side note - is there a better way to get this type of error to log? I wasn't able to see any indication of an error until I stepped through the code in a debugger.\r\n\n", "before_files": [{"content": "from urllib.parse import urlparse\n\nfrom bokeh.server.django.consumers import DocConsumer, AutoloadJsConsumer\n\nfrom .resources import Resources\nfrom .server import (\n    autoload_js_script, server_html_page_for_session\n)\n\nasync def doc_handle(self, body):\n    session = await self._get_session()\n    resources = Resources.from_bokeh(self.application.resources())\n    page = server_html_page_for_session(\n        session, resources=resources, title=session.document.title,\n        template=session.document.template,\n        template_variables=session.document.template_variables\n    )\n    await self.send_response(200, page.encode(), headers=[(b\"Content-Type\", b\"text/html\")])\n\n\nasync def autoload_handle(self, body):\n    session = await self._get_session()\n\n    element_id = self.get_argument(\"bokeh-autoload-element\", default=None)\n    if not element_id:\n        raise RuntimeError(\"No bokeh-autoload-element query parameter\")\n\n    app_path = self.get_argument(\"bokeh-app-path\", default=\"/\")\n    absolute_url = self.get_argument(\"bokeh-absolute-url\", default=None)\n\n    if absolute_url:\n        server_url = '{uri.scheme}://{uri.netloc}/'.format(uri=urlparse(absolute_url))\n    else:\n        server_url = None\n\n    resources = self.resources(server_url)\n    js = autoload_js_script(resources, session.token, element_id, app_path, absolute_url)\n\n    headers = [\n        (b\"Access-Control-Allow-Headers\", b\"*\"),\n        (b\"Access-Control-Allow-Methods\", b\"PUT, GET, OPTIONS\"),\n        (b\"Access-Control-Allow-Origin\", b\"*\"),\n        (b\"Content-Type\", b\"application/javascript\")\n    ]\n    await self.send_response(200, js.encode(), headers=headers)\n\n\nDocConsumer.handle = doc_handle\nAutoloadJsConsumer.handle = autoload_handle\n", "path": "panel/io/django.py"}], "after_files": [{"content": "from urllib.parse import urlparse\n\nfrom bokeh.server.django.consumers import DocConsumer, AutoloadJsConsumer\n\nfrom .resources import Resources\nfrom .server import (\n    autoload_js_script, server_html_page_for_session\n)\n\nasync def doc_handle(self, body):\n    session = await self._get_session()\n    resources = Resources.from_bokeh(self.application.resources())\n    page = server_html_page_for_session(\n        session, resources=resources, title=session.document.title,\n        template=session.document.template,\n        template_variables=session.document.template_variables\n    )\n    await self.send_response(200, page.encode(), headers=[(b\"Content-Type\", b\"text/html\")])\n\n\nasync def autoload_handle(self, body):\n    session = await self._get_session()\n\n    element_id = self.get_argument(\"bokeh-autoload-element\", default=None)\n    if not element_id:\n        raise RuntimeError(\"No bokeh-autoload-element query parameter\")\n\n    app_path = self.get_argument(\"bokeh-app-path\", default=\"/\")\n    absolute_url = self.get_argument(\"bokeh-absolute-url\", default=None)\n\n    if absolute_url:\n        server_url = '{uri.scheme}://{uri.netloc}/'.format(uri=urlparse(absolute_url))\n    else:\n        server_url = None\n\n    resources = self.resources(server_url)\n    js = autoload_js_script(session.document, resources, session.token, element_id, app_path, absolute_url)\n\n    headers = [\n        (b\"Access-Control-Allow-Headers\", b\"*\"),\n        (b\"Access-Control-Allow-Methods\", b\"PUT, GET, OPTIONS\"),\n        (b\"Access-Control-Allow-Origin\", b\"*\"),\n        (b\"Content-Type\", b\"application/javascript\")\n    ]\n    await self.send_response(200, js.encode(), headers=headers)\n\n\nDocConsumer.handle = doc_handle\nAutoloadJsConsumer.handle = autoload_handle\n", "path": "panel/io/django.py"}]}