Description
Modifies the HTML content of a file to replace all tags' href attributes, all <script> tags' src attributes, and all src attributes by default, also provides support for custom modification of tags and attribute with Django template tags, and adds {% load static %} to the beginning of the file.
Installation
To use the function, simply install the package with pip, by default beautifulsoup4 library will be in install using the code below but incase there is any problem, you can install it via pip:
pip install html2django
Usage
from djangohtml import djangoify
djangoify('index.html')
# modify the index.html file in place
Example
Suppose you have an HTML file named index.html that looks like this:
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
<link rel="stylesheet" href="styles.css">
<script src="script.js"></script>
</head>
<body>
<h1>Hello, World!</h1>
<img src="image.png">
</body>
</html>
Running the djangoify() function on this file:
djangoify('index.html')
will modify the file to look like this:
{% load static %}
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
<link href="{% static 'styles.css' %}" rel="stylesheet">
<script src="{% static 'script.js' %}"></script>
</head>
<body>
<h1>Hello, World!</h1>
<img src="{% static 'image.png' %}">
</body>
</html>
Here, the , <script>, and tags' href and src attributes have been replaced with Django template tags, and {% load static %} has been added to the beginning of the file.
Parameters
- file (str): The path to the input HTML file.
- custom_tag (str): Custom html tag to modify. To be used with the custom_attr parameter.
- custom_attr (str): Custom html attribute of the custom_tag.
- custom_value (any): The value of the - custom attribute.
Returns
None: The function modifies the input file in place.
Raises
FileNotFoundError: If the input file cannot be found or accessed.
Authors
Metadata
Release files for html2django 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| html2django-1.0.tar.gz | 4.1 kB | Without provenance | Details for html2django-1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| html2django-1.0-py3-none-any.whl | Python 3 | none | any | Details for html2django-1.0-py3-none-any.whl |
Total release size: 8.8 kB
Release files / html2django-1.0.tar.gz
| Download URL | html2django-1.0.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
450a966b83ec13d4f53d60168997b561a6a55b3268774d54428fd04f53367421
|
|
BLAKE2b-256 checksum How to use checksums |
6664023b0b39b668dea0f937168762a392d0be30090eb1e747c2acc1b381517c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Release files / html2django-1.0-py3-none-any.whl
| Download URL | html2django-1.0-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7485f04ea31a2d36046cae43bfdfeafbfc1e52ff79bb13fa1dcd379f21013933
|
|
BLAKE2b-256 checksum How to use checksums |
f4dd83dad510f2b446f91fc5183079f62435173781d27c1a5fab7ff75ff8d498
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Security for html2django 1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.