Python Django Projects scaffolding boilerplate automation

Viewed 358

I have django-cms project and i will use it as boilerplate, like when i got a project, i just run a command, it should generate initial setup/copy existing project with different name and changing some contenxt.

For example, i have wsgi.py file

"""
WSGI config for mysite project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings.dev")

application = get_wsgi_application()

So currently the project name is mysite but when i re-genrate the same project for another client/project, the project name should be different, like it will mywebsitepro

I mean, some text/code should be replaced into my given one.

Anyone has idea of how i can get it done? like when we run django command django-admin startproject <projectname> You may notice, everywhere of the first generated files name is same as what we given in command argument.

What is the possible solution of this? is there any tools like this?

1 Answers

Actually, as I understand it, you need a set of templates containing your source code so that you can replace some variables with values.

For this type of system, you should use a templating engine. And instead of reinventing the wheel, you can try out some out-of-the-box tools. For example Telosys (https://www.telosys.org), a lightweight code generator (free and open source) based on the well-known Velocity template engine (http://velocity.apache.org).

Some Python application templates are already available (not for Django but it can serve as an example):

See also this tutorial: https://www.slideshare.net/lguerin/telosys-tutorial-code-generation-for-a-python-web-application-based-on-bottle-and-sqlalchemy

Related