Comments (6)
try this:
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
asgi_application = get_asgi_application()
from channels.auth import AuthMiddlewareStack
from channels.http import AsgiHandler
from channels.routing import ProtocolTypeRouter, URLRouter
from django.conf import settings
from django.urls import path, re_path
from django_nextjs.proxy import NextJSProxyHttpConsumer, NextJSProxyWebsocketConsumer
http_routes = [re_path(r"", asgi_application)]
websocket_routers = []
if settings.DEBUG:
http_routes.insert(0, re_path(r"^(?:_next|__next|next).*", NextJSProxyHttpConsumer.as_asgi()))
websocket_routers.insert(0, path("_next/webpack-hmr", NextJSProxyWebsocketConsumer.as_asgi()))
application = ProtocolTypeRouter(
{
"http": URLRouter(http_routes),
## Just HTTP for now. (We can add other protocols later.)
"websocket": AuthMiddlewareStack(URLRouter(websocket_routers)),
}
)
from django-nextjs.
I do believe it's related to URLRouter(http_routes)
, within ProtocolTypeRouter
. This configuration will make urls.py along with settings.py failed to work.
from django-nextjs.
Hi, can you show me your asgi.py
file?
from django-nextjs.
This is the one I used and it's referenced from #4 (comment) as I couldn't find useful usage for this part in the tutorial.
"""
ASGI config for mysite project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
# application = get_asgi_application()
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.http import AsgiHandler
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django_nextjs.proxy import NextJSProxyHttpConsumer, NextJSProxyWebsocketConsumer
from django.conf import settings
from django.urls import path, re_path
http_routes = []
websocket_routers = []
if settings.DEBUG:
http_routes.insert(0, re_path(r"^(?:_next|__next|next).*", NextJSProxyHttpConsumer.as_asgi()))
websocket_routers.insert(0, path("_next/webpack-hmr", NextJSProxyWebsocketConsumer.as_asgi()))
application = ProtocolTypeRouter({
"http": URLRouter(http_routes),
## Just HTTP for now. (We can add other protocols later.)
"websocket": AuthMiddlewareStack(URLRouter(websocket_routers)),
})
from django-nextjs.
super, all work fine now.
I suggest publish this code into the README.md as settings for next.js v12 dev mode.
from django-nextjs.
Yeah, I'm on it, thanks.
from django-nextjs.
Related Issues (20)
- Can we use the Django==1.11.14 version with any code changes as its basic support version is Django==3.2? HOT 1
- _next/webpack-hmr' failed: / Too many redirects HOT 9
- Passing Data HOT 3
- Incorrect Type Annotations
- Request for compression support in django-nextjs HOT 1
- Having issues with NGINX HOT 2
- Not a problem just a deseparate need for help,please response HOT 3
- Does this support dynamic routing such as passing a slug? HOT 1
- Is it possible for me to add the second frontend? HOT 1
- Customizing the HTML Response: Fix hydration error with Nextjs 13+ app router HOT 1
- ASGI Mode Causes Timeout Errors in Next.js Server-Side Rendering HOT 3
- Error Page Sync HOT 11
- CSS/JS not loading in production HOT 2
- setup with django < 4.2
- Client-side navigation does not work with NextJS 13 + App router
- CookieError - Attempt to set a reserved key 'expires' HOT 1
- it very hard to understand how this app work
- for next.js v12 vercel.svg can not loaded HOT 1
- Want to pass allow_redirects parameter to render function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-nextjs.