Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
danialkeimasi committed Aug 8, 2023
1 parent 94365d6 commit 64b8a04
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 15 deletions.
2 changes: 2 additions & 0 deletions django_nextjs/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def _get_nextjs_request_headers(request: HttpRequest, headers: Union[Dict, None]
return {
"x-real-ip": request.headers.get("X-Real-Ip", "") or request.META.get("REMOTE_ADDR", ""),
"user-agent": request.headers.get("User-Agent", ""),
"pre_body": f"pre body django {request.path_info}",
"post_body": f"post body django {request.path_info}",
**({} if headers is None else headers),
}

Expand Down
10 changes: 10 additions & 0 deletions sample/next13/app/app/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Link from "next/link";

export default function Home() {
return (
<div>
<p>Index App</p>
<Link href="/app/second">Go To Second App</Link>.
</div>
);
}
10 changes: 10 additions & 0 deletions sample/next13/app/app/second/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Link from "next/link";

export default function Home() {
return (
<div>
<p>Second App</p>
<Link href="/app">Go To Index App</Link>.
</div>
);
}
12 changes: 10 additions & 2 deletions sample/next13/app/layout.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { headers } from "next/headers";

export default function RootLayout({ children }) {
const headersList = headers();
const preBody = headersList.get("pre_body");
const postBody = headersList.get("post_body");

return (
<html lang="en">
<body id="__django_nextjs_body">
<div id="__django_nextjs_body_begin" />
<div dangerouslySetInnerHTML={{ __html: preBody }} />
<h1>app router</h1>
<a href="/page">Go to Page</a>
{children}
<div id="__django_nextjs_body_end" />
<div dangerouslySetInnerHTML={{ __html: postBody }} />
</body>
</html>
);
Expand Down
3 changes: 0 additions & 3 deletions sample/next13/app/page.js

This file was deleted.

2 changes: 2 additions & 0 deletions sample/next13/pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export default function Document() {
<Head />
<body id="__django_nextjs_body">
<div id="__django_nextjs_body_begin" />
<h1>page router</h1>
<a href="/app">Go to App</a>
<Main />
<NextScript />
<div id="__django_nextjs_body_end" />
Expand Down
3 changes: 0 additions & 3 deletions sample/next13/pages/page.js

This file was deleted.

10 changes: 10 additions & 0 deletions sample/next13/pages/page/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Link from "next/link";

export default function Page() {
return (
<div>
<p>Index Page</p>
<Link href="/page/second">Go To Index Page</Link>.
</div>
);
}
10 changes: 10 additions & 0 deletions sample/next13/pages/page/second.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Link from "next/link";

export default function Page() {
return (
<div>
<p>Index Page</p>
<Link href="/page">Go To Index Page</Link>.
</div>
);
}
8 changes: 3 additions & 5 deletions sample/project/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@


{% block body %}
... the content you want to place at the beginning of "body" tag ...
... e.g. include the navbar template ...
pre body django {{ request.path_info }}
{{ block.super }}
... the content you want to place at the end of "body" tag ...
... e.g. include the footer template ...
{% endblock %}
post body django {{ request.path_info }}
{% endblock %}
10 changes: 8 additions & 2 deletions sample/project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@


async def nextjs_page(request):
return await render_nextjs_page(request)


async def nextjs_page_with_template(request):
return await render_nextjs_page(request, "index.html")


urlpatterns = [
path("admin/", admin.site.urls),
path("", nextjs_page),
path("page", nextjs_page),
path("app", nextjs_page),
path("app/second", nextjs_page),
path("page", nextjs_page_with_template),
path("page/second", nextjs_page_with_template),
path("", include("django_nextjs.urls")),
]

0 comments on commit 64b8a04

Please sign in to comment.