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

Update config.py for LazySettings issue #322

Closed
wants to merge 1 commit into from
Closed

Update config.py for LazySettings issue #322

wants to merge 1 commit into from

Conversation

kenanmasri
Copy link

@kenanmasri kenanmasri commented Jun 24, 2022

I had some problem:

Error reading webpack-stats.json. Are you sure webpack has generated the file and the path is correct?

When trying to use the utils from the package inside my python apps.
It means it might have been using Django's lazy settings I think. Thus my main project's settings.py would not be available:

user_config = getattr(settings, 'WEBPACK_LOADER', DEFAULT_CONFIG)

This would in turn give the DEFAULT_CONFIG. At least in my implementation (which is templatetags specifically).

This is my code for reference

a file called templatetags/core.py

  from webpack_loader.utils import get_as_tags as webpack_loader_get_as_tags

  @register.simple_tag(name="render_bundle_prefetch")
  def do_render_bundle_prefetch(
          bundle_name, extension=None, config='DEFAULT', suffix='',
          attrs=''):
      rendered_bundle = webpack_loader_get_as_tags(
          bundle_name, extension=extension, config=config, suffix=suffix,
          attrs=attrs, is_preload=True)
      rendered_bundle = "\n".join(rendered_bundle)
      rendered_bundle = mark_safe(rendered_bundle.replace('rel="preload"', 'rel="prefetch"'))
      return rendered_bundle

Anyway this is my suggestion. I have moved everything inside load_config.

@kenanmasri kenanmasri marked this pull request as ready for review June 24, 2022 13:31
This pull request was closed.
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

Successfully merging this pull request may close these issues.

2 participants