Skip to content

Add a settings.py to my setup.  #2

@Janus-sama

Description

@Janus-sama

Since the template is located inside the django_flex_widget directory, it is only practical and sensible to add configs to plug it to the settings.py so Django can map the template path to the widget template. It would also help in extending and creating custom HTML widgets.

Upon adding the necessary configuration to settings.py, you can import the custom template path using the TEMPLATES and DIRS settings. By creating a new dictionary for the custom template path, you can specify the location of your templates. For example:

TEMPLATES = [
    {
        # ...
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        # ...
    }
]

Next, you can extend your INSTALLED_APPS in settings.py to include your custom widgets. This ensures that your widgets are treated as a Django application and your custom templates are mapped correctly.

It is worth noting that when customizing and creating custom HTML widgets in Django, you are essentially building upon the internal mechanics of Django. Customizing templates will require creating a custom widgets directory and adding all of your necessary templates as static HTML files which could then extend existing templates. For example:

# Project Structure
 polls/
    __init__.py
    templates/
        admin/
            widgets/
                custom_widgets.html
    views/
templates/
    admin/
        base.html

In your admin/base.html, add:

{% block extrahead %}
    {{ block.super }}
    {% include 'admin/widgets/custom_widgets.html' %}
{% endblock %}

By following these methods, you are able to develop custom widgets that can improve your application's UI/UX experience with a high degree of success.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions