1
0

assets.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. """Helper functions for adding assets to the app."""
  2. from typing import Optional
  3. from reflex import assets
  4. from reflex.utils import console
  5. def asset(relative_filename: str, subfolder: Optional[str] = None) -> str:
  6. """DEPRECATED: use `rx.asset` with `shared=True` instead.
  7. Add an asset to the app.
  8. Place the file next to your including python file.
  9. Copies the file to the app's external assets directory.
  10. Example:
  11. ```python
  12. rx.script(src=rx._x.asset("my_custom_javascript.js"))
  13. rx.image(src=rx._x.asset("test_image.png","subfolder"))
  14. ```
  15. Args:
  16. relative_filename: The relative filename of the asset.
  17. subfolder: The directory to place the asset in.
  18. Returns:
  19. The relative URL to the copied asset.
  20. """
  21. console.deprecate(
  22. feature_name="rx._x.asset",
  23. reason="Use `rx.asset` with `shared=True` instead of `rx._x.asset`.",
  24. deprecation_version="0.6.6",
  25. removal_version="0.7.0",
  26. )
  27. return assets.asset(
  28. relative_filename, shared=True, subfolder=subfolder, _stack_level=2
  29. )