Thursday, January 31, 2019

django channels daphne static files

I'm on the latest Django 2.1.5, channels 2.1.6, daphne 2.2.4

Trying to get the static file to route through daphne.  I've tried using the default 'AsgiHandler' and tried both 'StaticFilesHandler' and 'StaticFilesWrapper'.  Here's my settings.py, routing.py setup and output:

My code works using 'python manage.py runserver'

import os

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)

----------------------------------


from django.conf.urls import url

from channels.http import AsgiHandler
from channels.routing import ProtocolTypeRouter, URLRouter

application = ProtocolTypeRouter({
    # Channels will do this for you automatically. It's included here as an example.
    "http": URLRouter([
        # AsgiHandler is "the rest of Django" - send things here to have Django
        # views handle them.
        url(r"^", AsgiHandler),
    ]),
})



----------------------------------

from django.conf.urls import url

from channels.staticfiles import StaticFilesHandler
from channels.routing import ProtocolTypeRouter, URLRouter

application = ProtocolTypeRouter({
    # Channels will do this for you automatically. It's included here as an example.
    "http": URLRouter([
        # AsgiHandler is "the rest of Django" - send things here to have Django
        # views handle them.
        url(r"^", StaticFilesHandler),
    ]),
})

2019-01-31 10:31:57,386 ERROR    Exception inside application: 'static_base_url'
  File "c:\python37\lib\site-packages\channels\http.py", line 202, in __call__
    await self.handle(body)
  File "c:\python37\lib\site-packages\asgiref\sync.py", line 108, in __call__
    return await asyncio.wait_for(future, timeout=None)
  File "C:\Python37\Lib\asyncio\tasks.py", line 388, in wait_for
    return await fut
  File "C:\Python37\Lib\concurrent\futures\thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "c:\python37\lib\site-packages\asgiref\sync.py", line 123, in thread_handler
    return self.func(*args, **kwargs)
  File "c:\python37\lib\site-packages\channels\http.py", line 233, in handle
    response = self.get_response(request)
  File "c:\python37\lib\site-packages\channels\staticfiles.py", line 68, in get_response
    return self.serve(request)
  File "c:\python37\lib\site-packages\channels\staticfiles.py", line 60, in serve
    return serve(request, self.file_path(request.path), insecure=True)
  File "c:\python37\lib\site-packages\channels\staticfiles.py", line 53, in file_path
    relative_url = url[len(self.scope["static_base_url"][2]) :]
  'static_base_url'


---------------------------------------------

from django.conf.urls import url

from channels.staticfiles import StaticFilesWrapper
from channels.routing import ProtocolTypeRouter, URLRouter

application = ProtocolTypeRouter({
    # Channels will do this for you automatically. It's included here as an example.
    "http": URLRouter([
        # AsgiHandler is "the rest of Django" - send things here to have Django
        # views handle them.
        url(r"^", StaticFilesWrapper),
    ]),
})

2019-01-31 10:36:28,617 ERROR    Traceback (most recent call last):
  File "c:\python37\lib\site-packages\daphne\http_protocol.py", line 179, in process
    "server": self.server_addr,
TypeError: __call__() got an unexpected keyword argument 'receive'

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3020c698-4cb3-4a29-8b65-d6f1e833aa9d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment