Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/loglux/djangotemplateconverter
DjangoTemplateConverter is a tool for converting HTML templates into Django templtes. It finds and copies static files (CSS, JS, images) and creates Django templates from HTML sections marked by comments.
https://github.com/loglux/djangotemplateconverter
bootstrap5 conver django hmtl-css html-templates python
Last synced: 16 days ago
JSON representation
DjangoTemplateConverter is a tool for converting HTML templates into Django templtes. It finds and copies static files (CSS, JS, images) and creates Django templates from HTML sections marked by comments.
- Host: GitHub
- URL: https://github.com/loglux/djangotemplateconverter
- Owner: loglux
- Created: 2024-07-25T22:31:26.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2024-08-02T12:56:38.000Z (6 months ago)
- Last Synced: 2024-08-02T18:45:50.406Z (6 months ago)
- Topics: bootstrap5, conver, django, hmtl-css, html-templates, python
- Language: Python
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Django Template Converter
## Description
`DjangoTemplateConverter` is a tool for converting HTML templates into Django templates. It finds and copies static files (CSS, JS, images) and creates Django templates from HTML sections marked by comments. Comments should start with the keyword `Start` and end with the keyword `End`. An important condition is that section names should be a single word (e.g., `AboutUs Start` instead of `About Us Start`).
## Features
- **Static Files Copy**: Copies all CSS, JS, and image files to the Django static folder.
- **Template Creation**: Creates separate Django templates for each section and forms a main base template `base.html`.
- **Navbar Link Update**: Updates links in the navbar to use Django's `{% url %}` template tag.
- **URLs Configuration**: Automatically generates a `urls.py` file based on the sections identified in the HTML.
- **Views Creation**: Creates a `views.py` file with a view function for each section.
- **Additional HTML File Processing**: Processes additional HTML files in the index directory, converting them into Django templates. Note that the method does not remove duplicate sections like the navbar or footer. These should be manually consolidated to prevent duplication in the final Django application.## Installation and Usage
### Dependencies
Make sure you have the following dependencies installed:
- Python 3.10+
- BeautifulSoup4
- urllib3### Installation
1. Clone the repository:
```sh
git clone https://github.com/loglux/DjangoTemplateConverter.git
```2. Navigate to the project directory:
```sh
cd DjangoTemplateConverter
```3. Install the dependencies:
```sh
pip install BeuatifulSoup4
```### Usage
1. Create an HTML file with sections marked by comments. For example:
```html
Header Content
Footer Content
```
It is recommended to combine the header and navbar into the same template called navbar, enclosing the necessary parts of the header and navbar within the same comments:
```htmlHeader ContentNavbar Content```
2. Run the script `django_template.py` by specifying the Django app name and the path to your HTML file:
```sh
python django_template.py
```### Example Usage
Example usage of the class:
```python
if __name__ == '__main__':
app_name = 'portfolio'
index_file = 'CryptoCoin-1.0.0/index.html'
converter = TemplateConverter(app_name, index_file)
converter.run()
```## License
This project is licensed under the MIT licence.