It's time for some hands-on experience building your first Django project!
Django's official website has the following to say about the web framework: "Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source."
Sounds like a pretty sweet deal! Learning to use Django will allow us to build what we want, without encountering many of the web development woes that come with building something from scratch or employing a microframework, e.g., Express.js or Flask.
To get a feel for what it's like to build a Django web application, let's focus on creating a simple project.
Build a Django web application that displays "hello, world".
To do this, you'll need the following:
hello_django
hello_app
urls.py
file in hello_django
urls.py
urlpatterns
if you used django-admin
to create your projectviews.py
file in hello_app
views.py
will contain a view called index_view
index_view
will render the index.html
template with context passed to the template i.e. "hello, world"templates
hello_django
and hello_app
folderstemplates
directory called index.html
settings.py
that is properly configured
TEMPLATES
variable in settings.py
hello_app
we're using
INSTALLED_APPS
variable in settings.py
pyproject.toml
file with Django listed as a dependencyFile Structure Preview: . ├── hello_app │ ├── __init__.py │ └── views.py ├── hello_django │ ├── __init__.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── manage.py ├── pyproject.toml ├── poetry.lock └── templates └── index.html
https://github.com/kenzie-se-q4/hello-django-<github_username>