Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STATIC_URL not found in context (Django 1.8) #53

Open
debnet opened this issue Apr 3, 2015 · 6 comments
Open

STATIC_URL not found in context (Django 1.8) #53

debnet opened this issue Apr 3, 2015 · 6 comments

Comments

@debnet
Copy link

debnet commented Apr 3, 2015

All is in the title. ;)

@debnet
Copy link
Author

debnet commented Apr 3, 2015

We created a patch for until a fix comes out:

# django.js monkey patch
# https://github.com/noirbizarre/django.js/issues/53
# settings not found in request context
try:
    from django.conf import settings
    from djangojs.context_serializer import ContextSerializer

    def _as_dict(self):
        data = self._as_dict()
        data.update({
            'STATIC_URL': settings.STATIC_URL,
            'MEDIA_URL': settings.MEDIA_URL,
            'LANGUAGES': settings.LANGUAGES,
            'LANGUAGE_CODE': settings.LANGUAGE_CODE,
        })
        return data

    ContextSerializer._as_dict = ContextSerializer.as_dict
    ContextSerializer.as_dict = _as_dict
except:
    pass

It lacks everything related to languages however.

@ribeiroct
Copy link

Hi,
I'm having this issue on Django 1.8. But i'm not really understanding and been able to figure out where this monkey patch should go.

@ribeiroct
Copy link

My workaround was to include manually the script tags, for now...

@ScottEAdams
Copy link

You can add the monkey patch pretty much anywhere (urls, views etc). Would also like to see a proper fix for this. Any ideas?

@pcompassion
Copy link

I'm not sure what I see is the same as yours.

Since I only needed context data in JsInitData, I overrode the ContextSerializer's as_data to include what I included using context_processors in the past and removed them from the context proccesors list.

settings.JS_CONTEXT_PROCESSOR

    def as_dict(self):
        data = super(CustomContextSerializer, self).as_dict()

        data.update(site_common_settings(self.request))
        data.update(annoter_settings(self.request))

        return data  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants