the red penguin
HOME ABOUT SITEMAP BLOG LOGIN

8. Building a lightweight project

The components of Django that we’ve just looked at are really just Python packages that we can import into whichever file structure we wish to create.

The tutor showed us how to create a lightweight site. The idea of this is to replace the helloworld functionality we’ve seen in the last few exercises.

We create a folder called lightweight_site and in it, a file called helloworld.py.

from django.http import HttpResponse
from django.conf.urls import url
from django.urls import path
from django.conf import settings
import sys
settings.configure(
    DEBUG=True,
    SECRET_KEY="ThisIsTheSecretKey",
    ROOT_URLCONF=__name__,
    MIDDLEWARE_CLASSES=(
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.middleware.clickjacking.XFrameOptionsMiddleware',
    ),
 )
def index(request):
    return HttpResponse('<html><head></head><body><p>Hello world!</p></body></html>')
urlpatterns = [
    path('', index)
]
if __name__ == "__main__":
    from django.core.management import execute_from_command_line
    execute_from_command_line(sys.argv)

      


Wednesday 20 October 2021, 459 views


Leave a Reply

Your email address will not be published. Required fields are marked *