Share it on social media

Table of contents

Published: April 7, 2022 Last modified: May 1, 2022

faster_dj_dev documentation: How to become a faster Django developer

    Installation

    Create a virtual environment:

    python -m virtualrnv env

    Activate it:

    • For Windows:
    env\Scripts\activate

    • For Linux/ Mac
    source env/bin/activate

    Install with

    pip:python -m pip install faster_dj_dev


    Example

    Let's use this tool to create a new Django project with all its configurations related to static, media and templates. Also, we will create a new Django app with it.

    But first, we need to initialize the project with this command (Each time you create a new project using this tool):

    faster_dj_dev --init --working-directory absolute_path_of_the_working_directory --project-folder only_name_of_the_django_project_folder

    Examples:

    • --working-directory C:\Users\selmi\Desktop\test
    • --project-folder config

    Then run this command

    faster_dj_dev --create_project --config-templates --config-static --config-media --initial-migrate --app main --run-server

    This command will create a Django project and a new app called main. It also add the configuration of the static, media files and templates, it will update your settings.py and urls.py file safely.


    Important

    Whether you are creating a new Django project or updating an old project, this package is useful and works for both cases.


    Create a new Django project

    This command will let you create and install a new Django project in less than 10 seconds.

    $ faster_dj_dev --init -wd C:\Users\selmi\Desktop\test -pf config
    • -wd (--working-directory)
    • -pf (--project-fodler)


    $ faster_dj_dev --create-project

    config is the folder name that contains the Django settings files.

    test  is the directory that contains the entire project and apps. You should include the absolute path of that folder, in case it doesn't exist, the program will create it in that given path.






    Create a new Django app


    With this command, you can add a new Django app to the project we have just created or update an existing Django project.

    Note: "main" is the app name you'll install.

    faster_dj_dev --app main





    Static files (settings and configuration)


    faster_dj_dev --config-static

    With this, we update the settings.py file to handle the static files of our Django project and it creates a new static folder if it doesn't exist.





    Media files (settings and configuration)


    faster_dj_dev --config-media

    With this, we update the settings.py and urls.py files to handle the media files of our Django project and it creates a new static folder if it doesn't exist.




    Configure templates (settings)


    faster_dj_dev --config-templates

    This command will update the settings.py file to handle templates files and creates a new templates folder if it doesn't exist.





    Install Django another package

    In addition to the configuration, this tool allows you to install some of the most used Django packages easily and in a matter of seconds.

    List includes:



    How it works:



    Let's install django-htmx to see how everything is done.

    faster_dj_dev --install django-htmx

    The tool will install the django-htmx using pip, add it to the installed apps list and update the middleware and even update the urls.py file of your Django project.

    #settings.py
    INSTALLED_APPS = [
        ...
        "main",
        "django_htmx",
    ]

    MIDDLEWARE = [
        ...
        "django_htmx.middleware.HtmxMiddleware",
    ]

    and at the end, it prints a clear message of the usage of that tool.

    ============ DJANGO HTMX USAGE ===========
    {% load django_htmx %}
    {% load static %}
    <!DOCTYPE html>
    <html lang="en">
            <head>
        <title>Django HTMX</title>
                    <meta charset="UTF-8">
                    <meta name="viewport" content="width=device-width, initial-scale=1.0">
                    <meta http-equiv="X-UA-Compatible" content="ie=edge">
            <script src="https://unpkg.com/htmx.org@1.7.0" integrity="sha384-EzBXYPt0/T6gxNp0nuPtLkmRpmDBbjg6WmCUZRLXBBwYYmwAUxzlSGej0ARHX0Bo" crossorigin="anonymous" defer></script>
                    {% django_htmx_script %}
            </head>

            <body>
            <!--CODE HERE-->
            </body>
    </html>
    Docs URL:       https://django-htmx.readthedocs.io/en/latest/installation.html
    =======================================


    How to install the other available packages

    - To install djangorestframework and django-cors-headers (yes, you can install multiple packages at once):

    faster_dj_dev -i djangorestframework -i django-cors-headers


    - To install Django Tailwind

    faster_dj_dev -i tailwind


    - To install django-unicorn

    faster_dj_dev -i django-unicorn



    Conclusion


    Over time, I'll add more functionalities that increase your Django productivity and more packages to install. Feel free to comment if anything isn't clear or you want to include a specific Django package to the list.


    Thanks.








    353 0
    Selmitech

    This is Selmi Abderrahim, the author and the admin of SelmiTech blog.

    Subscribe to our mail list

    No comments yet!