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

Attribute helpers for JSON data attributes #15

Open
kissgyorgy opened this issue Nov 3, 2024 · 0 comments
Open

Attribute helpers for JSON data attributes #15

kissgyorgy opened this issue Nov 3, 2024 · 0 comments

Comments

@kissgyorgy
Copy link
Owner

There are cases where frameworks configure behavior by setting a JSON object in a HTML element data attribute, e.g. Alpine.JS, Preline UI.
A helper is useful in these cases.

Real example with Preline UI:

  config = {
      "url": reverse("profile-picture-upload"),
      "acceptedFiles": "image/*",
      "maxFiles": 1,
      "singleton": True,
      "paramName": "profile_picture",
      "previewsContainer": "#profile-picture-preview",
      "headers": {
          "X-CSRFToken": get_token(request),
      },
  }

  with html.Div(
      class_="inline-block dz-max-files-reached",
      data_hs_file_upload=safe(json.dumps(config)),
  ):
      ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant