In our previous blog Introduction to Django, we discussed the Django’s features and architecture. In this blog, we will create a web application in Django.
For starting a new project, go to the folder where you want your project to be and run the command:
django-admin startproject django_proj
Django’s command-line utility for administrative tasks.manage.py is automatically created in each Django project. manage.py does the same thing as django-admin but takes care of a few things for you:
It puts your project’s package on sys.path.
It sets the DJANGO_SETTINGS_MODULE environment variable so that it points to your project’s settings.py file. In our case, in manage.py file you can see the following:
django-admin helpto display usage information and a list of the commands provided by each application.
django-admin versionto display the current Django version.
Apart from manage.py, you can see the django_proj folder, which is the name which we used for creating a project. Inside this folder, there is a file __init.py__ which is empty it just tells python that this is a python package.
-is used for all kinds of configurations for example database.
- is used for mapping URL to views. Right now, you will see :
urlpatterns = [
We will discuss it later when we run the application.
wsgi.py-Django’s primary deployment platform is WSGI (Web Server Gateway Interface). It is a specification that describes how a web server communicates with web applications, and how web applications can be chained together to process one request.
startproject management command sets up a simple default WSGI configuration for you.
python3 manage.py runserver
It will start your application at http://127.0.0.1:8000/
You can see the unapplied migrations warning on the terminal:
To access your Admin Interface, you need to initiate the database.
python3 manage.py migrate
It will create necessary tables or collections depending on your DB type(default is SQLite), necessary for the admin interface to run.
python3 manage.py createsuperuser
Then start your application again, as we saw in urls.py, where admin path is stated.
Thanks for reading!